I want that my string didn't contain *
,;
and $
. I use this code
private static boolean IsMatch(String s, String pattern) {
try {
Pattern patt = Pattern.compile(pattern);
Matcher matcher = patt.matcher(s);
return matcher.matches();
} catch (RuntimeException e) {
return false;
}
}
String regex ="[^*;$]";
System.out.println(IsMatch(url,regex));
But this method return always false. Can any one tell me what's the problem
Regular Expression basically defines a search pattern, pattern matching, or string matching. It is present in java. util. regex package.
Try using [^*;$]*
for your regex. It'll return true if your string doesn't contain any of *
, ;
and $
. I'm assuming you want your regex to match strings that don't contain any of those characters since you're already using ^
inside [
and ]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With