代码:
import re
m=re.match('zc','zcdd')
if m is not None:
print(m.group())
else:
print(m)
m=re.match('zc','ddzc')
if m is not None:
print(m.group())
else:
print(m)
m=re.search('zc','zcdd')
if m is not None:
print(m.group())
else:
print(m)
m=re.search('zc','ddzc')
if m is not None:
print(m.group())
else:
print(m)
m=re.findall('a','abacd')
print(m)
运行:
![python正则表达式一:match、search和findall python正则表达式一:match、search和findall](https://image.shishitao.com:8440/aHR0cHM6Ly93d3cuaXRkYWFuLmNvbS9nby9hSFIwY0RvdkwybHRaeTVpYkc5bkxtTnpaRzR1Ym1WMEx6SXdNVGN3TnpFMU1Ea3lPREk0T1RNeA%3D%3D.jpg?w=700&webp=1)