This is probably one of those simple things that I am missing, but I have not been able to find a solution that would solve my issue.
I have two strings that are in the following format:
s1 = '87, 72 Start I am a sentence finish'
s2 = '93, 83 Start I am a sentence end'
Following this answer, Replace all text between 2 strings python, I am able to replace a phrase when given a start and end word, as the following.
import re
s1 = '87, 72 Start I am a sentence finish'
s2 = '93, 83 Start I am a sentence end'
print(re.sub("Start.*?finish", '', s1, re.DOTALL).strip())
print(re.sub("Start.*?end", '', s2, re.DOTALL).strip())
>>> 87, 72
>>> 93, 83
In my case, I will have conditions where the starting word is the same, but the ending word could be different.
Is it possible to replace the desired phrase by providing only the starting word?
I have tried this, but it only replaces the starting word.
s1 = '87, 72 Start I am a sentence finish'
print(re.sub("Start.*?", '', v1, re.DOTALL).strip())
>>> 87, 72 I am a sentence finish