regex - Java detect special characters in a string -
i use regex
r="[^a-za-z0-9]+"; to detect if string has 1 or more chars other letters , digits;
then tried following:
pattern.compile(r).matcher(p).find(); i tested:
! @ # $ % ^ & * ( ) + =- [ ] \ ' ; , . / { } | " : < > ? ~ _ ` most of time, works except backsplash \ , caret ^.
e.g.
string p = "abcasd10^" (return false) string p = "abcasd10\\" (return false) anything miss?
the following code prints "found: true" when compile , run it:
class t { public static void main (string [] args) { string thepattern = "[^a-za-z0-9]+"; string theinput = "abskkel35^"; boolean isfound = pattern.compile(thepattern).matcher(theinput).find(); system.out.println("found: " + isfound); } } not sure why see different result...
Comments
Post a Comment