你为什么不尝试
word = 'two're.compile(r'b%sb' % word, re.I)
输出:
>>> word = 'two'>>> k = re.compile(r'b%sb' % word, re.I)>>> x = 'one two three'>>> y = k.search( x)>>> y<_sre.SRE_Match object at 0x100418850>
还忘了提及,你应该在代码中使用原始字符串
>>> x = 'one two three'>>> y = re.search(r"btwob", x)>>> y<_sre.SRE_Match object at 0x100418a58>>>>



