| ||
python search()以及mactch 的基本语法:
https://www.cnblogs.com/aaronthon/p/9435967.html
match()函数只检测字符串开头位置是否匹配,匹配成功才会返回结果,否则返回None
search()函数会在整个字符串内查找模式匹配,只到找到第一个匹配然后返回一个包含匹配信息的对象,
该对象可以通过调用group()方法得到匹配的字符串,如果字符串没有匹配,则返回None
-------------------------------------------------------------------------------
import reprint(re.match("func", "function"))
# 打印结果 <_sre.SRE_Match object; span=(0, 4), match='func'>
print(re.match("func", "function").span())
# 打印结果  (0, 4)
print(re.match("func1", "function"))
# 打印结果 None注意:print(re.match("func1", "function").span())会报错,因为取不到span
-------------------------------------------------------------------------------
import re
print(re.search("tion", "function"))
# 打印结果 <_sre.SRE_Match object; span=(4, 8), match='tion'>
print(re.search("tion", "function").span())
# 打印结果  (4, 8)
print(re.search("tion1", "function"))
# 打印结果 None
-------------------------------------------------------------------------------正则表达式挺全的一篇文章,备用:
https://www.cnblogs.com/Mars-wang/p/7027168.html
search , match :
https://www.cnblogs.com/gdjlc/p/11389869.html
 /1
 /1 