Regex : matches all occurences of repeating pattern one after each other

To make it very simple : how can I have two matches here ?

console.log(', , ,'.match(/,\s+,/g));

>Solution :

You want to, instead of matching the comma directly, use a "positive lookahead" to check for a , past the right edge of the match.

That way the next group can also match the ,:

console.log(', , ,'.match(/,\s+(?=,)/g));

Leave a Reply