0

I'm not looking to match everything between two characters, like in this question. I'm looking to match a specific phrase. For example:

cat {mouse ostrich dog ostrich} fish {ostrich} ostrich

I want to match the three 'ostrich' strings in the curly brackets, but not anything else. Is that possible?

1 Answers1

-2

If your engine supports \G (PCRE, ...) you could very well get along with

(?:\G(?!\A)|{) # match the start of the last match or {
[^{}]*?\K      # not { or } lazily, \K "forgets" the match thus far
ostrich        # ostrich literally

See a demo on regex101.com.

Jan
  • 42,290
  • 8
  • 54
  • 79