title: regex named group starting with but not ends with
body: <p>I have two regexes (simplified to be equal)</p>
  
  <pre><code>r'^(?P&lt;slug&gt;(^foo)[-\w]+)/$'
  
  r'^(?P&lt;slug&gt;(^foo)[-\w]+)/$'
  </code></pre>
  
  <p>I would to add an exclusion on the first to check for the end so the latter wins.</p>
  
  <p>For example:</p>
  
  <p><code>foobar/</code> should pass the first and never the latter</p>
  
  <p>I want <code>foobar-my-string/</code> to fail the first but match the latter</p>
  
  <p>I have tried @sdanzig's answer:</p>
  
  <pre><code>r'^(?P&lt;slug&gt;(^foo)[-\w]+(?!my-string$))/$'
  
  r'^(?P&lt;slug&gt;(^foo)[-\w]+)/$'
  </code></pre>
  
  <p>But it doesn't work I always get into the latter with strings that do or do not end with "my-string"</p>
  
  <p>I also tried it the other way around as my regexes are evaluated top to bottom, but it also doesn't work:</p>
  
  <pre><code>r'^(?P&lt;slug&gt;(^foo)[-\w]+(my-string$))/$'
  
  r'^(?P&lt;slug&gt;(^foo)[-\w]+(?!my-string$))/$'
  </code></pre>