title: Regex for route matching in PHP
body: <p>I am working on my mini url router in PHP. So far I've got regex for extracting variables in the url enclosed in {}(By looking at Symfony's router code) :</p>
  
  <pre><code>public function parse($pattern)
  {
      $matches = '';
      $variables = array();
      $pos = 0;
  
      preg_match_all('#\{\w+\}#', $pattern, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
  
      foreach ($matches as $match) 
      {
          $varName = substr($match[0][0], 1, -1);
  
          if(is_numeric($varName)) {
              throw new Exception('Argument cannot be a number');
          }
  
          if (in_array($varName, $variables)) {
              throw new \LogicException(sprintf('More then one occurrence of variable name "%s".', $varName));
          }
  
          $variables[] = $varName;
      }
  
      return ['variables' =&gt; $variables];
  }
  </code></pre>
  
  <p>So this method extracts the vars, now I need a regex to match the pattern of the route with the url. I started learning about regexes, but I still am not that good to wrap my head around this. </p>