import re
print(re.match("func", "function"))
C:Python27python.exe "C:/Users/TLCB/PycharmProjects/untitled2/new python/a3.py"
<_sre.SRE_Match object at 0x01CB6A30>
Process finished with exit code 0
import re
print(re.match("unc", "function"))
C:Python27python.exe "C:/Users/TLCB/PycharmProjects/untitled2/new python/a3.py"
None
re.match()只查找第1行是否匹配
re.search()查找所有行是否匹配
import re
a="dd'
'ccc'
'cc'"
print a
print(re.match("ccc", a,re.S))
C:Python27python.exe "C:/Users/TLCB/PycharmProjects/untitled2/new python/a3.py"
dd'
'ccc'
'cc'
None
Process finished with exit code 0
import re
a="dd'
'ccc'
'cc'"
print a
print(re.search("ccc", a,re.S))
C:Python27python.exe "C:/Users/TLCB/PycharmProjects/untitled2/new python/a3.py"
dd'
'ccc'
'cc'
<_sre.SRE_Match object at 0x00526A30>
Process finished with exit code 0