Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex - match a string, but only where the next word is not 'x'

Tags:

c#

regex

If I have this string:

"The quick brown fox jumped over the lazy dog. What a nice brown fox that is."

What regex would I use to match the text 'brown fox' but not where the following word is 'that', i.e. (matches in italic):

"The quick brown fox jumped over the lazy dog. What a nice brown fox that is."

like image 233
Paddy Avatar asked Sep 22 '10 09:09

Paddy


1 Answers

You need a zero-width negative lookahead assertion, i.e.,

brown fox(?! that)
like image 76
Heinzi Avatar answered Sep 22 '22 14:09

Heinzi