标准库,re
re.match(pattern, string),从字符串头,开始匹配
import re
result = re.match(r"hello", "hello world")
print(result.group()) # "hello"(匹配成功)
result = re.match(r"world", "hello world")
print(result) # None(匹配失败)
re.search(pattern, string),整个字符串扫描,匹配
result = re.search(r"world", "hello world")
print(result.group()) # "world"(匹配成功)
浙公网安备 33010602011771号