I have a regex that searches for
m =~ s/(this)|(that)/ "ONE" !!x $1 . "TWO" !!x $2 /eg
m = re.sub(r"(this)|(that)", ("ONE" * bool(match.group(1))) + ("TWO" * bool(match.group(2))), m, flags=re.EVAL)
Python has no strange language syntax related to regular expressions - they are performed in well behaved function calls.
So instead of a part of the call arguments that are executed on match, what you have is a callback function: all you have to do is to put a callable object as the second argument, instead of the substitution string. The callable receives the match object as its sole argument. In this case, all you need is an inline
if - so you can even define the callable as a lambda expression:
t = "this this that" m = re.sub(r"(this)|(that)", lambda x: "ONE" if x.group() == "this" else "TWO", t )