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>Looks to me like you are close. Just need to tweak your regex a bit:</p>

<pre><code>/package/(?P&lt;pk&gt;[a-z]+)/release/(?P&lt;version&gt;v\d{1,2}\.\d{1,2}\.\d{1,2})/?$
</code></pre>

<p>This would match any version that has three digits, and each one being either 1 or 2 numbers. For example:</p>

<pre><code>v0.0.1    # True
v1.0.10   # True
v99.99.99 # True
v1.0      # False
</code></pre>

<p>Depending on your requirements, you can tweak this to your specifications. I just took a guess based upon your URL above.</p>

python regex django