1.sub(一个或者多个规则,替换成的变量, 所要替代的变量)
ret = re.sub(r"\d+", '998', "python = 997")
s = re.sub('\d', "s", "123p")
re.sub("\n| ", '', html.xpath("//li[@itemprop='jobTitle']/text()")[0].strip())
2.findall(规则,搜寻的变量)
ret = re.findall(r"\d+", "python = 9999, c = 7890, c++ = 12345")
3.split 根据匹配进行切割字符串,并返回一个列表
ret = re.split(r":| ","info:xiaoZhang 33 shandong")
4.match(规则,变量),从第一个字符开始匹配
ret = re.match("H","Hello Python")
5.re.compile()
import re
str_ = "hello world"
M = re.compile("hello")
M1 = re.compile("o")
S = re.compile("o")
F = re.compile("o")
print(M.match(str_))
print(M1.match(str_))
print(S.search(str_))
print(F.findall(str_))