import re
s = "python java c c++ python2 python python3"
res = re.match("python", s)
res_2 = re.match("python2", s)
print("res:", res)
print(res.span())
print(res.group())
print("res_2:", res_2)
res_3 = re.search("python3", s)
print("res_3:", res_3)
res_4 = re.findall("python", s)
print("res_4:", res_4)
res_5 = re.findall(r"\d", s)
print(res_5)
res_6 = re.findall(r"\W", s)
print(res_6)
res_7 = re.findall(r"[a-zA-Z]", s)
print(res_7)
r = r"^[a-zA-Z0-9]{6,9}$"
s = "12345Az"
print(re.findall(r, s))
r = r"^[1-9][0-9]{5,10}$"
r_1 = r"[1-9][0-9]{5,10}"
s = "279968894"
print(re.match(r_1, s))
print(re.findall(r, s))
注意此处整体需加括号,否则findall返回每个分组内容
# 注意此处整体需加括号,否则findall返回每个分组内容
r = r"(^[\w-]+(\.[\w-]+)*@(qq|163|gmail)(\.[\w-]+)+$)"
# s = "[email protected]"
s = "[email protected]"
print(re.findall(r, s))
print(re.match(r, s))
# 使用match取出邮箱
print(re.match(r, s).group())