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
Post a Comment