title: Regular expression to match a Python integer literal
body: <p>What is a regular expression that will match any valid Python integer literal in a string?  It should support all the extra stuff like <code>o</code> and <code>l</code>, but not match a float, or a variable with a number in it.  I am using Python's <code>re</code>, so any syntax supported by that is OK. </p>
  
  <p><strong>EDIT</strong>: Here's my motivation (as apparently that's quite important).  I am trying to fix <a href="http://code.google.com/p/sympy/issues/detail?id=3182" rel="nofollow">http://code.google.com/p/sympy/issues/detail?id=3182</a>.  What I want to do is create a hook for IPython that automatically converts int/int (like <code>1/2</code>) to <code>Rational(int, int)</code>, (like <code>Rational(1, 2)</code>.  The reason is that otherwise it is impossible to make <code>1/2</code> be registered as a rational number, because it's Python type <code>__div__</code> Python type. In SymPy, this can be quite annoying because things like <code>x**(1/2)</code> will create <code>x**0</code> (or <code>x**0.5</code> with <code>__future__</code> division or Python 3), when what you want is <code>x**Rational(1, 2)</code>, an exact quantity.  </p>
  
  <p>My solution is to add a hook to IPython that automatically wraps all integer literals in the input with Integer (SymPy's custom integer class that gives <code>Rational</code> on division).  This will let me add an option to <code>isympy</code> that will let SymPy act more like a traditional computer algebra system in this respect, for those who want it.  I hope this explains why I need it to match any and all literals inside an arbitrary Python expression, which is why it needs to not match float literals and variables with numbers in their names.</p>
  
  <p>Also, since everyone's so interested in what I tried, here it is: not much before I gave up (regular expressions are hard). I played with <code>(?!\.)</code> to make it not catch the first part of float literals, but this didn't seem to work (I'd be curious if someone can tell me why, an example is <code>re.sub(r"(\d*(?!\.))", r"S\(\1\)", "12.1")</code>).</p>
  
  <p><strong>EDIT 2</strong>: Since I plan to use this in conjunction with <code>re.sub</code>, you might as well wrap the whole thing in parentheses in your answers so I can use <code>\1</code> :)</p>