title: How to properly match a Python string literal with a regular expression?
body: <p>This is part of a class project. I built a scanner using Java that scans Python code. Now I have to compare run times with a Flex implementation of a Python scanner.</p>
  
  <p>So I am trying to match a Python string literal using Flex. I am trying to convert the <a href="http://docs.python.org/2/reference/lexical_analysis.html#string-literals" rel="nofollow">string literal specification</a> from the Python docs to a C regular expression.</p>
  
  <p>This is what I have so far: </p>
  
  <p><code>[r|u|ur|R|U|UR|Ur|uR|b|B|br|Br|bR|BR]?('(([^\\]|[^\n]|[^'])|\\.)*'|\"(([^\\]|[^\n]|[^'])|\\.)*\"|'''([^\\]|\\.)*'''|\"\"\"([^\\]|\\.)*\"\"\")</code></p>
  
  <p>But when I apply it to the following text:</p>
  
  <pre><code>r'' lol
  r''
  </code></pre>
  
  <p>It matches both lines. I want it to match each <code>r''</code> separately and ignore anything outside the quotes.</p>