Reputation: 19333
I'm analyzing a regex pattern I found on a separate question on the VI SE site, and I'm having trouble breaking it down, i.e.:
\(.\{-}\zsPATTERN\)\{N}
How does this pattern do a replace operation on the N
th occurrence of PATTERN
(i.e. could someone please help me expand the logic in this regex)?
Thank you.
Upvotes: 2
Views: 118
Reputation: 626690
Here, the pattern matches N occurrences of a sequence of any 0+ chars, as few as possible, omitting this sequence and then matching the PATTERN
.
That is:
\(
- start of a grouping construct.\{-}
- any 0+ chars, as few as possible\zs
- omits the text matched so farPATTERN
- some PATTERN
\)
- end of the grouping construct\{N}
- a range / limiting quantifier, repeating the group pattern(s) N times.Upvotes: 2