regex - Python - extract numbers and commas from string (with re.sub) -


i have following string (python) :

test = "    +30,0 eur abcdefgh   " 

i want remove numbers , comma ",".

expected result: "30.0" 

so based on re doc tried :

test = re.sub('^[0-9,]', "", test) 

output is:

"    +30,0 eur abcdefgh   " 

nothing happened. why?

the ^ needs go inside brackets.

>>> re.sub('[^0-9,]', "", test) '30,0' 

to change comma decimal:

>>> '30,0're.sub('[^0-9,]', "", test).replace(",", ".") '30.0' 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -