regular expression for integer and decimal numbers

Andrew Durdin adurdin at
Fri Sep 24 03:15:48 CEST 2004

On 23 Sep 2004 17:51:17 -0700, gary <gary.wilson at> wrote:
> I want to pick all intergers and decimal numbers out of a string.
> Would this be the most correct regular expression to use?
> "\d+\.?\d*"

That will work for numbers such as 0123  12.345  12.  0.5 -- but it
won't work for the following:
0x12AB  .5  10e-3  -15  123L
If you want to handle some of those, then you'll need a more complicated regex.
If you want to accept numbers of the form .5 but don't care about 12.
then a better regex would be

More information about the Python-list mailing list