title: How to extract digits from a URL and save them in a variable?
body: <p>I have a forwarding request which involves a bunch of products with production ID. </p>
  
  <pre><code>http://www.example.com/abc/en_us/Products/Cards/Note-Cards/Laser-Note-Cards_05315.htm
  </code></pre>
  
  <p>to</p>
  
  <pre><code> www.example.com/products/cards/05315
  </code></pre>
  
  <p>So I want to make a regex pattern to match the four or five digit product ID in the original URL and use a variable to save it. Then we can reuse that variable to build the destination link.</p>
  
  <p>I have set up a rule like before, but it doesn't work. Could anybody here help me with this or give me some examples that I can imitate?</p>
  
  <pre><code>location ~ ^/abc/en_us/(?&lt;myvar&gt;[0-9][0-9][0-9][0-9]|[0-9][0-9][0-9][0-9][0-9]) {
   # use variable $myvar here
   #if ( $myvar = "sth" ) { ... }
   rewrite ^/$1/$2/$myvar;
  }
  </code></pre>