I have the following string (Python) :
test = " +30,0 EUR abcdefgh "
I want to remove everything but numbers and comma ",".
Expected result: "30.0"
So based on re doc I tried :
test = re.sub('^[0-9,]', "", test)
Output is:
" +30,0 EUR abcdefgh "
Nothing happened. Why?
The ^
needs to go inside the brackets.
>>> re.sub('[^0-9,]', "", test)
'30,0'
To change the comma to a decimal:
>>> '30,0're.sub('[^0-9,]', "", test).replace(",", ".")
'30.0'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With