Regex interpretaion in Django tutorial
<p>despite being familiar with the basics of regex, the tutorial for <a href="https://docs.djangoproject.com/en/1.10/intro/tutorial03/#writing-more-views" rel="nofollow">Django 1.10</a> does not go into much detail about how some regex generates dynamic links. 
I am looking at this specific snippet under the polls/urls.py: </p>

<pre><code>url(r'^(?P&lt;question_id&gt;[0-9]+)/$', views.detail, name='detail'),
</code></pre>

<p>Could someone go into detail about how that regex is interpreted? The quantifiers at the start of the capture group, <code>(?P&lt;question_id&gt;</code> do not make sense to me. Specifically, how does Django know that <code>&lt;question_id&gt;</code> is a foreign key?</p>

<p>It captures [0-9]+ under the name question_id. Then it passes the captured number to the view function as a parameter. You can try it with re functions. It is not Django specific.</p>

<pre><code>&gt;&gt;&gt; import re
&gt;&gt;&gt; re.match(r'^(?P&lt;question_id&gt;[0-9]+)/$', '122/').groupdict()
{'question_id': '122'}
</code></pre>

python regex django