filename = Baked Beans And Spam.txt
我可以理解正则表达式如何使用字符串:
f = self.filename
v = self.AdvanceReplace.GetValue() # from a TextCtrl box
s = re.sub(r'\sAnd\s',' & ',f)
prints Baked Beans & Spam
但是假设我想将第一个参数用作变量,例如v
:
s = re.sub(v,' & ',f)
打印Baked Beans And spam
。我怎样才能强制re.sub
接受这个作为变量?