JS regex splitting
2 answers
In your situation, you can simply use this regex:
var text = '123,456/,789,ABC';
var texts = text.split(/\b,/g);
console.log(texts); // ["123", "456/,789", "ABC"]
The idea is that the word boundary metacharacter \b,
will not match /,
because the backslash is not a word character, so there is no word boundary between /
and ,
.
RegExp test: http://regex101.com/r/qB6aT7/1
+3
source to share