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