I want to search if a sentence has particular pattern or not. Do nothing if not found. If pattern found, substitute pattern with another substring in the string.
line1 = "Who acted as `` Bruce Wayne '' in the movie `` Batman Forever '' ?"
#Desired Result: Who acted as ``Bruce_Wayne'' in the movie ``Batman_Forever'' ?
#This is what I have tried..
def findSubString(raw_string, start_marker, end_marker):
start = raw_string.index(start_marker) + len(start_marker)
end = raw_string.index(end_marker, start)
return raw_string[start:end]
phrase = findSubString(line1, "``", "''")
newPhrase = phrase.strip(' ').replace(' ', '_')
line1 = line1.replace(phrase, newPhrase)
Current Result: Who acted as ``Bruce_Wayne'' in the movie `` Batman Forever '' ?
So far, I managed to find the first occurrence in the sentence but not the next. How to search for all occurrences with matching pattern?
remodule).