title: Python Regular Expression searching backwards
body: <p>I need to extract a string from a directory like this:</p>
  
  <pre><code>my_new_string = "C:\\Users\\User\\code\\Python\\final\\mega_1237665428090192022_cts.ascii"
  ID = '1237665428090192022'
  m = re.match(r'.*(\b\w+%s)(?&lt;!.{%d})' % (ID, -1), my_new_string)
  if m: print m.group(1)
  </code></pre>
  
  <p>I need to extract 'mega' from the above <code>my_new_string</code>. At the moment the above just gets <code>mega_1237665428090192022</code> so how do I get it to ignore the ID number?</p>
  
  <p>To be honest I don't understand how these expressions work, even after consulting documentation. 
  What does the <code>r'</code> do? And how does the <code>?&lt;!.{%d}</code> work?</p>
  
  <p>edit: Thanks guys!</p>