I want to know if is possible to do this without checking for the regex pattern twice.
I am on python 3
pp = re.search(r'(.)(.+)\1(.+)', word)
word = re.sub(r'(.)(.+)\1(.+)', '', word)
salv = pp.groups()
word + = salv[0] + salv[0] + inverse(salv[1]) + salv[2]
There first I look for the matches, and then I remove the matches, but I am looking for the same regex patter twice. And I feel it can be done other way.
So what I want to do is:
Match a pattern, remove that pattern, and concat what I matched on a different way.