regex - Regular expression for "parts joined by a delimiter"? -
e.g. want test string comma-separated list, no empty elements. (that means string doesn't begin or end comma.)
procedurally, could/would (e.g. javascript):
function isvalid(str) { homecoming str.split(',').every(function (substr) { homecoming substr.length > 0; }); }
can accomplish regex? i'm struggling doing so, , maybe it's because i'm not experienced features lookahead.
thanks!
i may have actually.
/^[^,]+(,[^,]+)*$/
that's saying: start 1 or more non-commas, , if there's else, must comma followed 1 or more non-commas, repeated.
that seems work in cases i've tested:
// should pass: x xy x,y x,y,z // should fail: , x, ,x ,x, x,y, ,x,y ,x,y,
but i'm not sure if i'm missing cases.
regex
No comments:
Post a Comment