参考:https://www.icourse163.org/learn/BIT-1001870001?tid=1467473478#/learn/content?type=detail&id=1248909693&cid=1276198042
Raw String
主要函数
compile
def compile(pattern, flags=0):
"Compile a regular expression pattern, returning a Pattern object."
search
def search(pattern, string, flags=0):
"""Scan through string looking for a match to the pattern, returning
a Match object, or None if no match was found."""
match
def match(pattern, string, flags=0):
"""Try to apply the pattern at the start of the string, returning
a Match object, or None if no match was found."""
findall
def findall(pattern, string, flags=0):
"""Return a list of all non-overlapping matches in the string."""
split
def split(pattern, string, maxsplit=0, flags=0):
"""Split the source string by the occurrences of the pattern,
returning a list containing the resulting substrings.
If maxsplit is nonzero, at most maxsplit splits occur,
and the remainder of the string is returned as the final element
of the list."""
finditer
def finditer(pattern, string, flags=0):
"""Return an iterator over all non-overlapping matches in the
string. For each match, the iterator returns a Match object.
Empty matches are included in the result."""
sub
def sub(pattern, repl, string, count=0, flags=0):
"""Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
replacement repl. repl can be either a string or a callable;
if a string, backslash escapes in it are processed. If it is
a callable, it's passed the Match object and must return
a replacement string to be used."""
常用操作符
Match对象
属性
方法
最小匹配
RE库默认使用贪婪匹配算法