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>Try this:</p>

<p>str1 = "u'id': u'x'"</p>

<p>re.findall(r'u\'id\': u\'\d+\'',str1)</p>

<p>You need to escape single-quote(') because it's a special character</p>

python regex python-2.7 nsregularexpression