filename = Baked Beans And Spam.txt
I can understand how regex uses strings:
f = self.filename
v = self.AdvanceReplace.GetValue() # from a TextCtrl box
s = re.sub(r'\sAnd\s',' & ',f)
prints Baked Beans & Spam
But suppose I want to use the first argument as a variable such as v
:
s = re.sub(v,' & ',f)
prints Baked Beans And spam
. How can I force re.sub
to accept this as a variable?