Adam Waite
Adam Waite

Reputation: 18855

Regex match pattern inside of existing match

Not sure how to do this. Probably best illustrated with the following screen:

enter image description here

So I want the replaced text to read yo yo rather than yo.

That's both of the occurrences of {{.*}} rather than the large occurrence that wraps both of the search text.

Thanks.

Upvotes: 1

Views: 52

Answers (2)

devnull
devnull

Reputation: 123458

You could use a negated character class:

{{[^}]*}}

Upvotes: 1

Bohemian
Bohemian

Reputation: 424983

You've coded a greedy quantifier .*, which consumes as much as possible while still matching - ie it matches from the first {{ to the last }}.

You want a reluctant quantifier:

{{.*?}}

which matches as little as possible, while still matching - ie it will match from the first {{ to the next }}.

Upvotes: 2

Related Questions