I want to replace the beginning of each word in a sentence if the beginning matches string x, regardless of uppercase lowercase.
For example: s = "My fAther is your grandFAther and Family is important"
replacing "FA" with "zZ" in the beginning of each word in the sentence results in "My zZther is your grandFAther and zZamily is important".
A regex would be very helpful, but if you can't, other code would be ok. I honestly can't find an effective solution.
Also, if you can give me a regex for when you want to replace the word termination, it would be very nice. eg: "green blablaen enenbla" -> "grezz blablazz enenbla".
thank you very much :D!
my code:
input: s, value_to_replace, new_value
w = s.split()
for i in range(len(w)):
w[i] = re.sub(pattern='^' + value_to_replace, repl=new_value, string=w[i],flags=re.IGNORECASE)
return ' '.join(w)
But idk if this is efficient, it can somehow make a regex that applies over all the sentence, not over a separate word.