search 和 match 的区别:
import re
print(re.match("abc","abc xyz"))
print(re.match("xyz","abc xyz")) #匹配必须从第一个开始,
print(re.search("abc","abc xyz")) #包含就可以
print(re.search("xyz","abc xyz"))
search 和 match 的相同之处:
import re
searchobj=re.search(r"(.*)-is-(.*)","abc xyz-is-go") #在这里,search和match无区别
print(searchobj)
print(searchobj.group())
print(searchobj.group(0)) #abc xyz-is-go
print(searchobj.group(1)) #abc xyz
print(searchobj.group(2)) #go