I just encountered a problem. I am trying to match a capturing group repeatedly, but it apparently only matches the last found
Example of what i want to do:
Input: 1:100,2:50,3:40 ENDLEVEL
Used: ([0-9]+:[0-9]+)+ ENDLEVEL
Expected matched groups: 1:100, 2:50, 3:40
Matched groups: 3:40
I have, prior to this, seen a question about this problem, where the answer was to use the {num}, but I am unsure of how I would use it in my case. Please excuse my dumb yet learning ass and help me if you can, thanks in advance
P.S. From Regex101: A repeated capturing group will only capture the last iteration. Put a capturing group around the repeated group to capture all iterations or use a non-capturing group instead if you're not interested in the data.
>Solution :
If you want to match your three values separately, you can use a positive lookaround, which will attempt to see whether the match ([0-9]+:[0-9]+) is followed by:
- an optional comma,
- any character,
- a space
- the
ENDLEVELstring
Here’s the final regex:
[0-9]+:[0-9]+(?=,?.* ENDLEVEL)
Check the demo here.