I have a python pattern that I want to replace in two different ways.
Pattern: <br><b>[Ss][1-2]:[0-9]*-
1)replace by " "
2)replace s/S by Author
I can do the first one as it is a simple replacement, but I am not sure how can I do the second replacement as it depends upon input pattern and only a part of the expression has to be replaced.
This is working for case 1, where I just replace by blanks.
text="<br><b>S1:2- you are wrong. I don't think so. <br><b>S2:2- you are wrong"
newtext=re.sub("(<br><b>[Ss][1-2]:[0-9]*-)\s*", ' ',text)
print(newtext)
Can we have a variable expression in the replacement string?
Replaced text
<br><b>Author1:2- you are wrong. I don't think so. <br><b>Author2:2- you are wrong