match
匹配string 开头,成功返回Match object, 失败返回None,只匹配一个。
import re
x='ccaabb'
if re.match("aa",x):
print '1111111'
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/eeeee/a9.py
Process finished with exit code 0
import re
x='aabb'
if re.match("aa",x):
print '1111111'
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/eeeee/a9.py
1111111
search
在string中进行搜索,成功返回Match object, 失败返回None, 只匹配一个。
import re
x='aabb'
if re.search("aa",x):
print '1111111'
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/eeeee/a9.py
1111111
import re
x='ccaabb'
if re.search("aa",x):
print '1111111'
C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/eeeee/a9.py
1111111
import re
x='ccaabb'
if not re.search("kk",x):
print '1111111'