String test1 = "This is my test string";
I want to match a string which does not contain "test"
I can do it with
Pattern p = Pattern.compile(".*?^(test).*?")
and it works but at most of sites like Regular Expressions and negating a whole character group
^(?!.*test).*$
is suggested which did not work for me.
As per my understanding ^(test)
is sufficient so why ^(?!.*test).*$
is required?