【发布时间】:2014-05-14 09:29:42
【问题描述】:
search() 来匹配字符串。下面是我的代码
import re
s = "hello world"
if re.search(r'hello world other exter string',s):
print 'match success'
else:
print 'no match'
在上面的代码中,它没有给我匹配。即使“hellow world”是给定字符串的一部分。我也尝试使用 re.match() 但得到相同的结果。
【问题讨论】:
-
首先阅读docs。你可以简单地做
s in 'hellow world other exter string' -
参数顺序错误,但“hello world”永远不会匹配示例字符串(“hello”与“hellow”)。