Home > Article > Backend Development > Regular expressions and the use of Python Re library
The content of this article is about regular expressions and the use of Python Re library. Now I share it with everyone. Friends in need can refer to the content of this article
When the regular expression contains escape characters, use raw stringMain functions of Re library Example
import re match = re.match(r'[1 - 9]\d{5}','BIT 100081') print(match.group(0))# match 函数从一个字符串的开始位置起匹配正则表达式,所以变量 match 应该等于 # None,所以上述代码会抛异常,正确的写法是先对 match 进行判断
pat is a regular expression object compiled from the regular expression string form. You can directly use the above 6 functions of the Re library.Re library match objectAttributes of match object Greedy matching and minimum matching of Re libraryRe library uses greedy matching by default, that is, output Match the longest stringRelated recommendations:
Usage and difference between greedy mode and non-greedy mode in Python regular expressions
videocapture library produces python video high-speed transmission program
The above is the detailed content of Regular expressions and the use of Python Re library. For more information, please follow other related articles on the PHP Chinese website!