假设给出以下字符串:
stri = "Date 26 March 1256\nDate of death\n27 January 1756\n25 January 1567\n death"
现在我只想提取紧随其后的日期Date of death
,即27 January 1756
。
我做到了这一点:
>>> regex = re.compile(r"Date of death.*?[0-9][0-9]? [A-z]+ [0-9]{4}", re.DOTALL)
>>> print regex.findall(stri)
['Date of death\n27 January 1756']
但我只想27 January 1756
进行一次正则表达式搜索。