regex - How to remove all whitespaces in string and get exactly one number?( Python) -
i have string. example:
str= '\n 4 420 700 – 6 219 000 \n '
or
'\n 4\xa0420\xa0700 – 6\xa0219\xa0000\xa0 \n'
in case number: 4420700
. number can there. 3 333 999 233
, example.
i had tried solution:
>>> import re >>> re.sub(r'\d','',str) '4420700621900016'
could me?
do split , replace.
>>> st = '\n 4 420 700 – 6 219 000 \n ' >>> re.sub(r'\d', '',st.split('–')[0]) '4420700'
or
st.split('–')[0].strip().replace(' ', '')
Comments
Post a Comment