Very simple regex

I want a regular expression that will ignore the sentence containing the character "XYZ". I use this, but it does not work.

<td>(.+[^XYZ])</td> 
+4
source share
2 answers

To match a string that does not contain the string "XYZ", you can use a negative scan :

 ^(?:(?!XYZ).)*$ 

If you just want to verify that the string does not contain any of these characters at any position, use the negative character class:

 ^[^XYZ]*$ 
+3
source

"(. + [^ XYZ])" means "at least one character followed by neither X, Y, Z.

Comparing everything that does not contain X, Y, Z, works with "([^ XYZ] *)" or "([^ XYZ] +)" if you want to get empty matches.

+1
source

Source: https://habr.com/ru/post/1308636/


All Articles