title: nginx location regex multiple elements
body: <p>I want to create one location regex for an endpoint that I currently serve using the following four rules.</p>
  
  <pre><code>location ~* ^/api/(?&lt;version&gt;.*)/(?&lt;service&gt;.*)(/.*/.*/.*/.*)$ {
  ...
  }
  
  location ~* ^/api/(?&lt;version&gt;.*)/(?&lt;service&gt;.*)(/.*/.*/.*)$ {
  ...
  }
  
  location ~* ^/api/(?&lt;version&gt;.*)/(?&lt;service&gt;.*)(/.*/.*)$ {
  ...
  }
  
  location ~* ^/api/(?&lt;version&gt;.*)/(?&lt;service&gt;.*)(/.*)$ {
  ...
  }
  </code></pre>
  
  <p>That allow an access to my APIs using the following routes: </p>
  
  <pre><code>https://myapp.mydomain.com/api/v1/anyservice/foo
  https://myapp.mydomain.com/api/v2/anyservice/foo/bar
  https://myapp.mydomain.com/api/v1/anotherservice/foo/bar/thingy
  https://myapp.mydomain.com/api/v1/anotherservice/foo/bar/thingy/owl
  </code></pre>
  
  <p>I have tried many solutions. For example:</p>
  
  <pre><code>location ~* "^/api/(?&lt;version&gt;.*)/(?&lt;service&gt;.*)(/.*){1,4}$" {
  ...
  }
  </code></pre>
  
  <p>or </p>
  
  <pre><code>location ~* "^/api/(?&lt;version&gt;.*)/(?&lt;service&gt;.*)(/.*)*$" {
  ...
  }
  </code></pre>
  
  <p>None of the solution I've tried has worked. Any idea ?</p>