title: Illegal escape character error in Java regex
body: <p>I've read <a href="http://download.oracle.com/javase/tutorial/essential/regex/index.html" rel="nofollow">the manual</a>, and at the end there was an exercise:</p>
  
  <blockquote>
    <p>Use a backreference to write an expression that will match a person's name only if that person's first name and last name are the same.</p>
  </blockquote>
  
  <p>I've written the next program <a href="http://pastebin.com/YkuUuP5M" rel="nofollow">http://pastebin.com/YkuUuP5M</a><br>
  But when I compile it, I'm getting an error:</p>
  
  <pre><code>PersonName.java:18: illegal escape character
  p = Pattern.compile("([A-Z][a-zA-Z]+)\s+\1");
                                        ^
  </code></pre>
  
  <p>If I rewrite 18 line in this way:</p>
  
  <pre><code>pattern = Pattern.compile(console.readLine("%nEnter your regex: "));
  </code></pre>
  
  <p>and write the pattern in the console, then the program works fine. Why I can't use the pattern as in the 1st program case and is there some way to fix it?</p>