s1 ='999' s2 = '99.99' mypat = re.compile('(^([0-9]+[.]+[0-9]+)|([0-9])$)') rate= mypat.search(s1) print rate.group() >>> print rate.groups() ('9', None, '9') >>> rate=mypat.search(s2) >>> print rate.group() 99.99
I need to get price = float(rate.group()). Price=999 or Price=99.99.
I think there is a problem when s1='999', when I do this:
>>> rate = mypat.search(s1) >>> price = float(rate.group()) >>> print price 9.0
I only get 9.0, I need to get 999.0. I think my way of doing rate.group() is wrong, can someone help me so I can get 999.0.