Scan through string looking for the first location where the regular expression pattern produces a match, and return a corresponding MatchObject instance. Return None if no position in the string matches the pattern; note that this is different from finding a zero-length match at some point in the string.
import re
regex = r"(?P<relevant_info>France'09)"
test_str = "Sentence : i leaved in France'09."
matches = re.finditer(regex, test_str, re.MULTILINE)
for match in matches:
print(match.group('relevant_info'))
从文档(https://docs.python.org/2/library/re.html#re.search)中,搜索不是返回
True
或False
:试试这个:
输出:
看看https://regex101.com/r/18NJ2E/1
TL;博士
相关问题 更多 >
编程相关推荐