INPUT :包含字串 CASE NO.: Appeal (civil) 648 of 2007 介于兩者之間。
輸出:案例編號:上訴(民事)2007 年第 648 號
我想提取以單詞 CASE NO.(Case Insensitive) 開頭并以一年的第一次出現結尾的字串。
我嘗試了以下代碼,該代碼與起始部分配合良好。
case_no = re.search(r"(?=Case No.)(\w \W ){5}", contents,re.IGNORECASE)
if case_no:
print(case_no.group())
uj5u.com熱心網友回復:
我會在這里使用一個惰性點來匹配最近發生的年份CASE NO.:
inp = "The string is enclosed CASE NO.: Appeal (civil) 648 of 2007 in between."
m = re.search(r'\bCASE NO\.:.*?\b\d{4}\b', inp)
print(m.group()) # CASE NO.: Appeal (civil) 648 of 2007
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/461243.html
