Capture semantic version in django url
<p>I have the following url
<code>
http://localhost:8000/api/package/printf/release/v0.0.1
</code></p>

<p>I need to capture the version at the end. What is the right way for the same. The url regex that i have now is</p>

<p><code>
/package/(?P&lt;pk&gt;[a-z]+)/release/(?P&lt;version[a-z]+)/$
</code></p>

<p>The semantic version should be passed as a single parameter and not as multiple int with <code>major</code> and <code>minor</code> version etc as different parameters.</p>

<p>You may rely on negated character class <code>[^/]</code> (that matches any character but <code>/</code>) and also make the last <code>/</code> optional by adding a <code>?</code> (1 or 0 occurrences) quantifier after it:</p>

<pre><code>/package/(?P&lt;pk&gt;[^/]+)/release/(?P&lt;version&gt;[^/]+)/?$
</code></pre>

<p>See the <a href="https://regex101.com/r/UZQFPd/1" rel="nofollow">regex demo</a></p>

python regex django