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>You have misplaced single quotes and you should use <code>\d+</code> instead of just <code>\d</code>:</p>

<pre><code>&gt;&gt;&gt; s = "u'id': u'2'"
&gt;&gt;&gt; re.findall(r"u'id'\s*:\s*u'\d+'", s)
["u'id': u'2'"]
</code></pre>

python regex python-2.7 nsregularexpression