Tuesday, 10 December 2019

Find all strings except one string using regex





I want to match all strings except the string "ABC".
Example:



 "A"     --> Match
"F" --> Match
"AABC" --> Match

"ABCC" --> Match
"CBA" --> Match
"ABC" --> No match


I tried with [^ABC], but it ignores "CBA" (and others).


Answer



^(?!ABC$).*



matches all strings except ABC.


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