title: Regular Expression and escape sequences
body: <p>I have a file which contains the list of regular expressions to look for in db.</p>
  
  <p>one such pattern is <code>(/|\)cmd\.com$</code>. But when i use it with re module, it throws up the below error.  If i use the re pattern as  <code>(/|\\\\)cmd\.com$</code>,it works.</p>
  
  <p>So, the question is when i read from a file in to variable for EX: a, how do i convert it to a reg pattern with four backward slashes so that it starts working with python re module.</p>
  
  <p>Also, how do we escape such escape sequences when reg pattern is assigned to a variable EX: "a" below.</p>
  
  <p>Any help on this is appreciated.</p>
  
  <pre><code>import re
  a='(/|\)cmd\.com$'
  re.compile(a)
  
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/lib/python2.6/re.py", line 190, in compile
      return _compile(pattern, flags)
    File "/usr/lib/python2.6/re.py", line 245, in _compile
      raise error, v # invalid expression
  sre_constants.error: unbalanced parenthesis
  </code></pre>
  
  <p>Thx,
  Santhosh</p>