title: Regular expression to confirm whether a string is a valid Python identifier?
body: <p>I have the following definition for an Identifier:</p>
  
  <pre><code>Identifier --&gt; letter{ letter| digit}
  </code></pre>
  
  <p>Basically I have an identifier function  that  gets a string from a file and tests it to make sure that it's a valid identifier as defined above.</p>
  
  <p>I've tried this:</p>
  
  <pre><code>if re.match('\w+(\w\d)?', i):     
    return True
  else:
    return False
  </code></pre>
  
  <p>but when I run my  program every time it meets an integer it  thinks that  it's a valid identifier.</p>
  
  <p>For example </p>
  
  <pre><code>c = 0 ;
  </code></pre>
  
  <p>it  prints <code>c</code> as a valid identifier which is fine, but it also prints <code>0</code> as a valid identifer.</p>
  
  <p>What  am I doing  wrong here?</p>