It took longer than expected.
re — Regular expression operations
Python3 - Regular Expression HOWTO
What does the “r” in pythons re.compile(r’ pattern flags’) mean?:
the r
string prefix is not specifically related to regex’s, but to strings generally in Python.
Normal strings use the backslash character as an escape character for special characters (like newlines):
1
2
3
print('this is \n a test')
this is
a test
The r
prefix tells the interpreter not to do this:
1
2
print(r'this is \n a test')
this is \n a test
re.match只匹配字符串的开始,如果字符串开始不符合正则表达式,则匹配失败,函数返回None;而re.search匹配整个字符串,直到找到一个匹配。
PYTHON的RE模块理解(RE.COMPILE、RE.MATCH、RE.SEARCH)
这个里面例子挺多的
正则—re模块的基础用法(re.match() /单个字符匹配/ 多个字符匹配)