Mar-09-2022, 10:34 PM
You most make test strings to see what happens,and no loop before have test this first.
import re string_object = '''\ == History == === Further reading === My car is blue 2 + 2 = 4 ++= & hello=''' pattern = re.compile(r'={2,}.+') processed = pattern.sub(repl='', string=string_object) print(processed.strip())
Output:My car is blue
2 + 2 = 4
++= & hello=
So your regex should work fine and added .strip()
to remove the new line that sub leave.