javascript - Regex match commas after a closing parentheses -
in javascript, trying split following string
var s1 = "(-infinity, -3],(-3,-2),[1,infinity)";
into array
["(-infinity, -3]","(-3,-2)","[1,infinity)"]
by using statement
s1.split(/(?=[\]\)]),/);
to explain, want split string commas follow closing square bracket or parenthesis. use ahead (?=[\]\)]),
so, doesn't match commas. when change (?![\]\)]),
, matches every commas. please suggest problem in regex.
your logic backwards. (?=...)
look-ahead group, not look-behind. means s1.split(/(?=[\]\)]),/);
matches if next character simultaneously ]
or )
, ,
, impossible.
try instead:
s1.split(/,(?=[\[\(])/);
Comments
Post a Comment