this is my text '123,456/,789,ABC' and I want to split by ',' but not split '/,'.
var text = '123,456/,789,ABC';
var texts = text.split(/[^/],/g);
console.log(texts)
result is [ '12', '456/,78', 'ABC' ]
but I expect [ '123', '456/,789', 'ABC' ]
For your situation you can simply use this regexp:
var text = '123,456/,789,ABC';
var texts = text.split(/\b,/g);
console.log(texts); // ["123", "456/,789", "ABC"]
The idea is that word boundary metacharacter \b, will not match /, because backslash is not word character, so there is no word boundary between / and ,.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With