1 回答

TA貢獻1818條經驗 獲得超3個贊
如果您的文本在日期之前有 STAND DER 信息,如圖所示,您可以使用以下內容。
法典
import re
re.findall(r'(?<=STAND DER INFORMATION\s)\D{3,4}\s\d{4}', s, re.MULTILINE)
解釋
# s is text string
# <=STAND DER INFORMATION\n - look behind for STAND DER INFORMATION followed by \n
# \D is non-digit (so 3 or 4 non-digits)
# \d digits (so four digit date)
# re.MULTILINE - multiline flag to allow matches across multiple lines
測試
s = """9.DATUM DER ERTEILUNG DER ZULASSUNG/VERL?NGERUNG DER ZULASSUNG
10.STAND DER INFORMATION
Juni 2019
Rezeptpflicht/Apothekenpflicht
Rezept- und apothekenpflichtig, wiederholte Abgabe verboten."""
dates = re.findall(r'(?<=STAND DER INFORMATION\n)\D{3,4}\s\d{4}', s, re.MULTILINE)
print(dates)
輸出
['Juni 2019']
添加回答
舉報