Wednesday, February 15, 2017

Regular expression to check a String not contain a word

For example, the string is "type1, type2, type3"

I want that if the string contains type2, the java match shall return false to me.

The regular expression shall be

?! is negative lookahead. ?!type2 means shall contain type2, then .* means any character.

There is a good online java regular expression test

No comments:

Post a Comment