newb: Simple regex problem headache

crybaby joemystery123 at
Fri Sep 21 23:04:40 CEST 2007

import re

s1 =' 25000 '
s2 = ' 5.5910 '

mypat = re.compile('[0-9]*(\.[0-9]*|$)')
rate =
price = float(
print price

I get an error when it hits the whole number, that is in this format:
s1 =' 25000 '
For whole number s2, mypat catching empty string.  I want it to give
me 25000.
I am getting this error:

    price = float(
    ValueError: empty string for float()

Anyone knows, how I can get 25000 out of s2 = ' 5.5910 '
using regex pattern, mypat = re.compile('[0-9]*(\.[0-9]*|$)').  mypat
works fine for real numbers, but doesn't work for whole numbers.


More information about the Python-list mailing list