3 回答

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊
word = 'two're.compile(r'\b%s\b' % word, re.I)
>>> word = 'two'>>> k = re.compile(r'\b%s\b' % 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"\btwo\b", x)>>> y<_sre.SRE_Match object at 0x100418a58>>>>

TA貢獻(xiàn)1825條經(jīng)驗(yàn) 獲得超4個(gè)贊
re.search(r"\btwo\b", x)
"\b"
"\x08"
"\\b"
r"\b"

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超8個(gè)贊
re.search("\btwo\b", x)
\b
print("foo\bbar")fobar
"\btwo\b"
two
x = 'one two three'
re.search
compile
\b
"\\btwo\\b"
r"\btwo\b"
).
添加回答
舉報(bào)