Monday 15 July 2013

How can detect one string contain one of several characters using java regex -


I have a variable length string, I want to know if there are many characters in this string or not. For example:

  "sadsdd $ sss ^ de ~"   

I have to find out if there is any of the following in this string: $ ^ ~ . Java string.matches ?

  "sadsdd $ sss ^ de ~" .how can I do this using the .matches ("[^ + + + + + +]"?    

Use a pattern and a matcher for this:

  pattern pattern = Pattern .compile ("[$ ~ ^]"); Matcher matcher = pattern.matcher (input); If (matcher.find ()) {// has special characters} other {// does not contain special characters}    

No comments:

Post a Comment