Friday 4 October 2019

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



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."


Answer



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



brown fox(?! that)

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...