title: Why do I get a parsing exception for this regex?
body: <p>I have the following patterns in a web service constructor:</p>
  
  <pre><code>rUsername = Pattern.compile("[A-z0-9]{4,30}");
  rPassword = Pattern.compile("[A-z0-9!@#$%&amp;*()=+-\\\\s]{6,30}");
  rQuestion = Pattern.compile("[A-z0-9\\\\s?]{5,140}");
  rAnswer = Pattern.compile("[A-z0-9\\\\s]{1,30}");
  </code></pre>
  
  <p>If I only have 2 slashes instead of the 4 there when I deploy my web application I get a parsing exception from Tomcat.</p>
  
  <p>The username one works fine, but I seem to be having issues with the password, question and answer. The password will match "testasdas" but not "test1234", the question will not match anything with a space in it and the answer doesn't seem to match anything.</p>
  
  <p>I want the password to be able to match lowercase and uppercase letters, numbers, spaces and the symbols I threw in there. The question one should be able to match lowercase and uppercase, numbers, spaces and '?', and the answer just uppercase and lowercase letters, spaces and numbers.</p>
  
  <p>EDIT: The patterns have changed to these:</p>
  
  <pre><code>rPassword = Pattern.compile("[A-Za-z0-9!@#$%&amp;*()=+\\s-]{6,30}");
  rQuestion = Pattern.compile("[A-Za-z0-9\\s?]{5,140}");
  rAnswer = Pattern.compile("[A-z0-9\\s]{1,30}");
  </code></pre>
  
  <p>These are more or less how I want, but as pointed out in an answer I'm being quite restrictive on my password field which probably isn't a good idea. I don't hash anything before I save it because this is a college project nobody will ever use and I know that is a bad idea in the real world but it was not part of the requirements for the project. I do however have to stop SQL injection attacks, which is why everything is so restrictive. The idea was to mainly disallow the use of <code>'</code> which every SQL attack I know of needs to work, but I don't know how to disallow only that character alone.</p>