Astaroth
Astaroth

Reputation: 2291

Regex: How to capture a group that is followed by '+' (greedy plus)?

Just say I have the following text to be processed by regex:

  red red red blue

To match the text, I use the following regex:

  (red\s*)+(blue)

Now, my question is that how to capture the first groups (not the first group) ?

Upvotes: 0

Views: 61

Answers (1)

m4573r
m4573r

Reputation: 990

Just add parenthesis around what you want to capture, in this case the whole +ed group:

((red\s*)+)(blue)

Upvotes: 2

Related Questions