regex - Replace string by matching using regular expression python -
original string:
necessary information leave comment unnecessary information
required string:
necessary information
i have multiple strings in above mentioned 'original string' format. want remove 'leave comment' , 'unnecessary information'.
since 'leave comment' common in string can build regular expression on that? , use in
string.replace( string , pattern )
the pattern here regular expression. how can write re this?
>>> s 'necessary information leave comment unnecessary information' >>> re.sub(r'\sleave comment.*', '', s) 'necessary information'
Comments
Post a Comment