title: PHP regex preg_match separate variables in url
body: <p>I have string</p>
  
  <pre><code>$string = 'foo/{id}/bar/{name}';
  </code></pre>
  
  <p>and I am trying to do regex filtering</p>
  
  <p>wanted output:</p>
  
  <pre><code>$matches = [
    0 =&gt; 'foo/{id}/bar/{name}',
    1 =&gt; 'id',
    2 =&gt; 'name'
  ]
  </code></pre>
  
  <p>I got so far: (regex is my weakness)</p>
  
  <pre><code>preg_match('~^' . $magic . '$~', $string, $matches)
  </code></pre>
  
  <blockquote>
    <p>edit: there are *n number of {variable} in url</p>
  </blockquote>