I know that re.sub(pattern, repl,text)
can substitute when pattern matches, and then return the substitute
my code is
text = re.sub(pattern, repl, text1)
I have to define another variable to to check whether it modified
text2 = re.sub(pattern, repl, text1)
matches = text2 != text1
text1 = text2
and, it has issues, e.g. text1='abc123def'
, pattern = '(123|456)'
, repl = '123'
, after replace , it is same, so matches
is false, but it actually matches.