title: Why do I not need to escape a Regex character if it is read from console in Java?
body: <p>Please see the following programs:</p>
  
  <p><strong>UseArgs.java</strong></p>
  
  <pre><code>import java.util.regex.*;
  
  class UseArgs {
      public static void main(String [] args) {
          String foo = args[0];
          String bar = args[1];
  
          Pattern p = Pattern.compile(foo);
          Matcher m = p.matcher(bar);
  
          while(m.find()) {
              System.out.print("Found at index: " + m.start() + "\n");
          }
      }
  }
  </code></pre>
  
  <p><strong>UseConsole.java</strong></p>
  
  <pre><code>import java.util.regex.*;
  import java.io.Console;
  
  class UseConsole {
      public static void main(String [] args) {
          Console console = System.console();
  
          String foo = console.readLine("foo: ");
          String bar = console.readLine("bar: ");
  
          Pattern p = Pattern.compile(foo);
          Matcher m = p.matcher(bar);
  
          while(m.find()) {
              System.out.print("Found at index: " + m.start() + "\n");
          }
      }
  }
  </code></pre>
  
  <p>So in order to work with UseArgs I need to call the program as follows:</p>
  
  <pre><code>MacBook-Pro:~ koraytugay$ java UseArgs \\d 4
  Found at index: 0
  </code></pre>
  
  <p>but for <strong>UseConsole</strong>, please see how I do <strong>not</strong> need to escape "any digit" character:</p>
  
  <pre><code>MacBook-Pro:~ koraytugay$ java UseConsole
  foo: \d
  bar: 4
  Found at index: 0
  </code></pre>
  
  <p>What is the reason behind the difference in the behaviours? I tried, but could not find any documentation, why we do <strong>not</strong> need to escape when the expression is read using the Console.</p>