I am trying to use a regex to match a list of elements separated by a comma in JavaScript.
The regex I use is the following: ([a-z]+)(?:,([a-z]+))*
, but I am not able to get all the matched groups, only the first and the last.
I made a regex101 to illustrate my problem: https://regex101.com/r/lIkE8k/5.
Is there something I’m missing?
2
Answers
Given your sample
bold,italic,underlign,blink
and what you appear to want, this regex would workhttps://regex101.com/r/b3exXD/1
This simple regex gives you all capture groups when using
matchAll
.