title: PHP preg_match part of url
body: <p>I am trying to create a url router in PHP, that works like django's.  </p>
  
  <p>The problems is, I don't know php regular expressions very well.  </p>
  
  <p>I would like to be able to match urls like this:</p>
  
  <pre><code>/post/5/
  /article/slug-goes-here/
  </code></pre>
  
  <p>I've got an array of regexes:</p>
  
  <pre><code>$urls = array(      
    "(^[/]$)" =&gt; "home.index",     
    "/post/(?P&lt;post_id&gt;\d+)/" =&gt; "home.post",    
  );
  </code></pre>
  
  <p>The first regex in the array works to match the home page at <code>/</code> but I can't get the second one to work.</p>
  
  <p>Here's the code I am using to match them:</p>
  
  <pre><code>foreach($urls as $regex =&gt; $mapper) {
      if (preg_match($regex, $uri, $matches)) {
      ...
      }
  }
  </code></pre>
  
  <p>I should also note that in the example above, I am trying to match the <code>post_id</code> in the url: <code>/post/5/</code> so that I can pass the <code>5</code> along to my method.</p>