Using regex to match a specific pattern in Python
<p>I am trying to create <strong>regex</strong> that matches the following pattern:</p>

<p><em>Note</em> : <strong><code>x</code> is a number e.g. 2</strong></p>

<p><strong><em>Pattern:</em></strong></p>

<pre><code>u'id': u'x'                # x = Any Number e.g: u'id': u'2'
</code></pre>

<p>So far I have tried the folllowing:</p>

<pre><code>Regex = re.findall(r"'(u'id':u\d)'", Data)
</code></pre>

<p>However, no matches are being found.</p>

<p>This regex will match your patterns:</p>

<p><code>u'id': u'(\d+)'</code></p>

<p>The important bits of the regex here are:</p>

<ul>
<li>the brackets <code>()</code> which makes a capture group (so you can get the information</li>
<li>the digit marker <code>\d</code> which specifies any digit 0 - 9</li>
<li>the multiple marker <code>+</code> which means "at least 1"</li>
</ul>

<p>Tested on the following patterns:</p>

<pre><code>u'id': u'3'
u'id': u'20'
u'id': u'250'
u'id': u'6132838'
</code></pre>

python regex python-2.7 nsregularexpression