I have a text string which contains a repeating pattern, each repetion separated by the next by the .
(dot) character. The pattern may
end in a _123
(underscore followed by a sequence of digits), and I want to catch those digits in a dedicated capturing group.
The RegEx (ECMAScript) I have built mostly works:
https://regex101.com/r/iEzalU/1
/(label(:|+))?(w+)(?:_(d+))?/gi
However, the (w+)
part acts greedy, and overtakes the (?:_(d+))?
part.
Adding a ?
to make w+
non-greedy (w+?)
works, but now I have a capturing token for each character matched by w
How can I make this regex such that w+
acts greedy but still does not overtake the _(d+)
part?
Otherwise, is it possible to capture all tokens matched by the non-greedy w+?
, as a single match? (some capturing/non-capturing groups magic?)