title: Find a string that contains X but not Y
body: <p>I want to perform regular expression operations on urls. I have these two routes on my site:</p>
  
  <ul>
  <li>domain.tld/clermont-ferrand/63000-cedex-01/</li>
  <li>domain.tld/clermont-ferrand/63000-cedex-01/in-a-25-km-radius/</li>
  </ul>
  
  <p>I am using the regular expression <code>[0-9a-z\-]+</code> to match 63000-cedex-01 (note that 63000-cedex-01 can be any postal code formatted with hyphens instead of spaces).</p>
  
  <p>Now the problem comes up when someone tries to access an url like this:</p>
  
  <p>domain.tld/clermont-ferrand/in-a-25-km-radius/</p>
  
  <p>The regular expression will consider this route as valid, which is something I don't want.</p>
  
  <p>Is it possible to tell regex to search for a hyphen separated alphanumerical pattern that doesn't contain "in-a-25-km-radius".</p>
  
  <p>I tried these two regex and they don't work:</p>
  
  <ul>
  <li><code>((?!in-a-\d+-(km|mile|miles)-radius)|[0-9a-z\-]+)</code></li>
  <li><code>(?(?=[0-9a-z\-]+)([0-9a-z\-]+)|(in-a-\d+-(km|mile|miles)-radius))</code></li>
  </ul>
  
  <p><strong>EDIT</strong></p>
  
  <p>OK basically on my route file for my MVC framework I have these two routes:</p>
  
  <blockquote>
    <p>/event/{status:(ongoing|past|upcoming)}/{category_slug:[a-z-]+}-event/in/{city_slug:[a-z-]+}/{postal_code_slug:[0-9a-z-]+}/</p>
  </blockquote>
  
  <p>which matches a path like:</p>
  
  <blockquote>
    <p>/event/ongoing/music-event/in/clermont-ferrand/63000-cedex-01/</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>/event/{status:(ongoing|past|upcoming)}/{category_slug:[a-z-]+}-event/in/{city_slug:[a-z-]+}/{postal_code_slug:[0-9a-z-]+}/in-a-{radius:\d+}-{unit:(km|mile|miles)}-radius/</p>
  </blockquote>
  
  <p>which matches a path like:</p>
  
  <blockquote>
    <p>/event/upcoming/film-event/in/beverly-hills/90210/in-a-40-miles-radius/</p>
  </blockquote>
  
  <p>Unfortunately, the first route also matches:</p>
  
  <blockquote>
    <p>/event/past/manga-and-anime-event/in/montreal/in-a-200-km-radius/</p>
  </blockquote>
  
  <p><strong>EDIT</strong></p>
  
  <p>The regex should match strings like these:</p>
  
  <ul>
  <li><p>9600</p></li>
  <li><p>ax-85000</p></li>
  <li><p>ad327</p></li>
  <li><p>36505-962</p></li>
  <li><p>biqq-1zz</p></li>
  <li><p>gx11-1aa</p></li>
  </ul>
  
  <p>and <strong>not</strong> match strings like these:</p>
  
  <ul>
  <li><p>in-a-200-km-radius</p></li>
  <li><p>in-a-1-mile-radius</p></li>
  <li><p>in-a-85-miles-radius</p></li>
  </ul>