So I have a string, "this-is-a-big-tool"
and swap out THIS and TOOL for different words but maintain BIG
import re
test = "this-is-a-big-tool"
s = [("a","b"), ("a","d"), ("c","d")]
for a,b in s:
result = re.sub("this-[\w]+-[\w]+-[big|giant]-tool", "%s-moves-big-%s" % (a,b), test)
print(result)
The issue is that say the only thing I care about is THIS, BIG, TOOL. I want to swap THIS and TOOL but keep BIG. and I dont care about the other words.
So my goal is to do something like:
a-is-a-big-b
a-is-a-giant-d
c-is-a-giant-d
The issue is that i figured out the regex, but how to i pass BIG or GIANT into the replace portion of the code?
result = re.sub("this-[\w]+-[\w]+-[big|giant]-tool", "%s-moves-big-%s" % (a,b), test)
How Do I pass This ---^ into --^