参考地址:https://docs.python.org/3/library/re.html
本文中的方法是从python官网摘抄整理的,为了给自己看
1、re.compile
prog = re.compile(pattern)
result = prog.match(string)
等价于
result = re.match(pattern, string)
不过re.compile这种更加高效
2、re.search(pattern, string, flags=0)
Scan through string looking for the first location
3、re.match(pattern, string, flags=0)
If zero or more characters at the beginning of string match the regular expression pattern
4、re.fullmatch(pattern, string, flags=0)¶
If the whole string matches the regular expression pattern
5、re.split(pattern, string, maxsplit=0, flags=0)
6、re.findall(pattern, string, flags=0)
7、re.finditer(pattern, string, flags=0)¶
8、re.sub(pattern, repl, string, count=0, flags=0)¶
9、re.subn(pattern, repl, string, count=0, flags=0)
10、re.escape(pattern)¶
11、re.purge()¶