How to match a regular expression with exactly one digit in it using python regex?
<p>I am trying to match a string with exactly one digit in it. e.g. '5', '4', '3', etc. I am using the <code>re</code> library in python to help me use regex.</p>

<p>I have the following three flags that are being set with respective if statements:</p>

<pre><code>import re

if re.match(r'\d{2}:\d{2}:\d{2}', item):
    timeflag = True

if re.match(r'\d{4}', item):
    voltflag = True   

if re.match(r'^\d{1}', item):
    socflag = True
</code></pre>

<p>Here is the weird part: when I pass an item with a value say <code>'2754'</code>, the <code>socflag</code> still gets set to <code>True</code>, even though it is only supposed to be true when matching a string with only one digit, like <code>'5'</code>.</p>

<p>I am suspecting that my regex syntax is incorrect. So, how do I match a one digit string using python regex?</p>