title: Unescaped "." still matches when used in a negation group
body: <p>I made, what I believed to be, an error in a regular expression in Java recently but when I test my code I don't get the error I expect.</p>
  
  <p>The expression I created was meant to replace a password in a string that I received from another source. The pattern I used went along the lines of: "password: [^\\s.]*", the idea being that it would match the word "password" the colon, a space, then any characters except for a space or a full-stop (period). I would then replace the instance with "password: XXXXXX" and therefore mask it.</p>
  
  <p>The obvious error should be that I have forgotten to escape the full-stop. In otherwords the proper expression should have been "password: [^\\s\\.]*". Thing is, if I don't escape the full-stop the code still works!</p>
  
  <p>Here's some sample code:</p>
  
  <pre><code>import java.util.regex.*;
  
  public class SimpleRegexTest {
  
      public static void main(String[] args) {
          Pattern simplePattern = Pattern.compile("password: [^\\s.]*");
          Matcher simpleMatcher = simplePattern.matcher("password: newpass. Enjoy.");
          String maskedString = simpleMatcher.replaceAll("password: XXXXXX");
          System.out.println(maskedString);
      }
  
  }
  </code></pre>
  
  <p>When I run the above code I get the following output:</p>
  
  <pre><code>password: XXXXXX. Enjoy.
  </code></pre>
  
  <p>Is this a special case, or have I completely missed something?</p>
  
  <p>(edit: changed to "escape the full-stop")</p>
  
  <p>Michael Borgwardt: I couldn't think of another term to describe what I was doing apart from "negation group", sorry for the ambiguity.</p>
  
  <p>Aviator: In this case, no, a space won't be in the password. I didn't make the rules ;-).</p>
  
  <p>(edit: doubled up the slashes in the non-code text so it displays properly, added the ^ which was in the code, but not the text :-/)</p>
  
  <p>Sundar: Fixed the double slashes, SO seems to have it's own escape characters.</p>