title: Java detect special characters in a string
body: <p>I use regex </p>
  
  <pre><code>r="[^A-Za-z0-9]+"; 
  </code></pre>
  
  <p>to detect if a string has one or more chars other than letters and digits;</p>
  
  <p>Then I tried the following:</p>
  
  <pre><code>Pattern.compile(r).matcher(p).find();
  </code></pre>
  
  <p>I tested: </p>
  
  <pre><code>! @ # $ % ^ &amp; * ( ) +  =- [ ] \ ' ; , . / { } | " : &lt; &gt; ? ~ _ `
  </code></pre>
  
  <p>Most of the time, it works except backsplash \ and caret ^. </p>
  
  <p>e.g. </p>
  
  <pre><code>String p = "abcAsd10^"    (return false)
  String p = "abcAsd10\\"   (return false) 
  </code></pre>
  
  <p>Anything I miss?</p>