remo remo - 1 year ago 135
Java Question

Java regex: check if word has non alphanumeric characters

This is my code to determine if a word contains any non-alphanumeric characters:

String term = "Hello-World";
boolean found = false;
Pattern p = Pattern.Compile("\\W*");
Matcher m = p.Matcher(term);
found = true;

I am wondering if the regex expression is wrong. I know
would matches any non-word characters. Any idea on what I am missing ??

Answer Source

Change your regex to:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download