title: java, regular expression, need to escape backslash in regex
body: <p>With reference to below question - 
  <a href="https://stackoverflow.com/questions/1701839/backslash-problem-with-string-replaceall">String.replaceAll single backslashes with double backslashes</a></p>
  
  <p>I wrote a test program, and I found that the result is true in both cases, whether I escape the backslash or not.  This may be because 
  - \t is a recognized Java String escape sequence. (Try \s and it would complain). 
  - \t is taken as literal tab in the regex. 
  I am somewhat unsure of the reasons. </p>
  
  <p>Is there any general guideline about escaping regex in Java.  I think using two backslashes is the correct approach.  </p>
  
  <p>I would still like to know your opinions. </p>
  
  <pre><code>public class TestDeleteMe {
  
    public static void main(String args[]) {
      System.out.println(System.currentTimeMillis());
  
      String str1 = "a    b"; //tab between a and b 
  
      //pattern - a and b with any number of spaces or tabs between 
      System.out.println("matches = " + str1.matches("^a[ \\t]*b$")); 
      System.out.println("matches = " + str1.matches("^a[ \t]*b$")); 
    }
  }
  </code></pre>