title: Java Regex to not allow String Special Characters
body: <p>I want to set a password which do not allow specific special characters like </p>
  
  <pre><code>-_\
  </code></pre>
  
  <p>and my regular expression is as follows</p>
  
  <pre><code>PatternCompiler compiler = new Perl5Compiler();
  PatternMatcher matcher = new Perl5Matcher();
  pattern = compiler.compile("^(?=.*?[a-zA-Z])(?=.*?[0-9])([A-Za-z0-9-/-~][^\\\\\\\\_\-]*)$");
  </code></pre>
  
  <p>It is working partially. If i place unwanted special characters between the string and start of the string still it is matching the password </p>
  
  <pre><code>P@ssword123    --correct
  -password@123  --it should not match
  -passowrd"11   --it should not match
  \password123   --it should not match
  _@111Password  --it should not match
  p@sswor"123    --correct
  </code></pre>
  
  <p>Any where in the string if i find -_\ regular expression should not match. 
  Using Apache api for matching pattern in java</p>