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

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -