I am trying to search through a load of text(located in the variable whole) for the word “he” this is then to be replaced by “she”
I then want to search through the text again and replace “she” with he.
however the regular exprssions below are overiding each other – meaning in this example the text will be all “he”
My question – is there anyway of combining the regular expressions and doing both operations in one go?
#jackNew.heShe() == she
#jillNew.heShe() == he
whole=re.sub(r'(?i)\bhe\b', jackNew.heShe(), whole)
whole=re.sub(r'(?i)\bshe\b', jillNew.heShe(), whole)
many thanks for your help.
You can make use of the fact that in
re.sub(pattern, repl, string, count=0, flags=0)gives