tags:

views:

51

answers:

2

Hello

I want a regular expression which will ignore the sentence containing "XYZ" character. I am using this but this is not working

"(.+[^XYZ])"

Thanks in advance

+3  A: 

To match a line not containing the string "XYZ" you can use a negative lookahead:

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

If you just want to check that the line doesn't contain any of those characters in any position, use a negative character class:

^[^XYZ]*$
Mark Byers
+1  A: 

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

Matching anything that doesn't contain X,Y,Z works with "([^XYZ]*)", or "([^XYZ]+)" if you want want empty matches.

Florian Diesch