The differences between match and search

match () starts from the first character to find, if the character does not match the first return None, do not continue to match the string is determined whether the beginning or the entire string matching speed.
search () will find the entire string until it finds a match.
 
import re
print(re.match('hello', 'hello world').span())
print(re.match('hello', 'hihelloworld'))
Print (the re.search ( 'Hello', 'Hello World') span ().)
Print (the re.search ( 'Hello', 'hihelloworld') () span.)
The output is:
(0,. 5)
None
( 0, 5)
(2,
7) ----------------
Disclaimer: This article is CSDN blogger "waiting for someone smile Dian 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/weixin_42523181/article/details/81749121

Guess you like

Origin www.cnblogs.com/xingkongzhizhu/p/11505041.html
Recommended