regex - Regular Expression in Python using re.split and pattern -


i have string this:

string ='arcelormittal invests =e2=82=ac87m in new process cuts emissions=20'

i want take out =e2=82=ac , =20

but when use,

pattern ='(=\w\w)+' a=re.split(pattern,string) 

it returns

['arcelormittal invests ', '=ac', '87m in new process cuts emissions', '=20', ''] 

you may use re.findall

>>> s = 'arcelormittal invests =e2=82=ac87m in new process cuts emissions=20' >>> re.findall(r'(?:=\w{2})+', s) ['=e2=82=ac', '=20'] >>>  

use re.sub if want remove chars.

>>> re.sub(r'(?:=\w{2})+', '', s) 'arcelormittal invests 87m in new process cuts emissions' 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -