Home >Backend Development >Python Tutorial >What is the python re.match function? Learn how to use the python match function.
#With the previous article "Detailed explanation of Python regular expressions, tell you what are Python regular expressions?" 》Linkage, this article describes the method of using the python re.match function, and comes with tables and examples to analyze the use of the Python match function.
re.match Try to match a pattern from the starting position of the string. If the matching is not successful at the starting position, match() will return none.
Related recommendations: "Python Tutorial"
Function syntax:re.match(pattern, string, flags=0)Function parameter description:
Matching regular expression | |
The string to match. | |
Flag bit is used to control the matching method of regular expressions, such as: whether to be case-sensitive, multi-line matching, etc. |
Matches the string of the entire expression. group() can enter multiple group numbers at once, in which case it will return a tuple containing the values corresponding to those groups. | |
Returns a tuple containing all group strings, from 1 to the contained group number. |
#!/usr/bin/python # -*- coding: UTF-8 -*- import re print(re.match('www', 'www.runoob.com').span()) # 在起始位置匹配 print(re.match('com', 'www.runoob.com')) # 不在起始位置匹配The output result of the above example is:
(0, 3) None
The above is the detailed content of What is the python re.match function? Learn how to use the python match function.. For more information, please follow other related articles on the PHP Chinese website!