我正在使用此代碼:(?i)(?<!\d)Item.*?1A.*?Risk.*?Factors.*?\n*(.+?)\n*Item.*?1B獲取以下文本:ITEM 1A. RISK FACTORSIn addition to other information in this Form 10-K, the following risk factors should be carefully considered in evaluating us and our business because these factors currently have a significant impact or In addition to other information in this Form 10-K, the following risk factors should be carefully considered in evaluating us and our business because these factors currently have a significant impact or ITEM 1B.但它不會抓取捕獲組中的任何內容,除非它是這樣的一段:ITEM 1A. RISK FACTORSIn addition to other information in this Form 10-K, the following risk factors should be carefully considered in evaluating us and our business because these factors currently have a significant impact or ITEM 1B.
2 回答

拉莫斯之舞
TA貢獻1820條經驗 獲得超10個贊
嘗試
(?i)(?<!\d)Item.*?1A.*?Risk.*?Factors.*?\n*((.*\n*)+)\n*Item.*?1B
為了您未來的正則表達式頭痛,一個令人難以置信的資源: https ://regex101.com
干杯-

心有法竹
TA貢獻1866條經驗 獲得超5個贊
您的正則表達式匹配任意數量的換行符,然后是一行上任意數量的文本,然后是任意數量的換行符 - 它只在換行符之間尋找一個“段落”,因為.
它不會跨行捕獲。
嘗試用類似的東西替換它[\s\S]
,這將捕獲所有內容 - 包括換行符、段落、文本、空格、任何你想要的東西。特別值得注意的是,這將捕獲任意數量的段落,它們之間有任意數量的空格。
(?i)(?<!\d)Item.*?1A.*?Risk.*?Factors\n*([\s\S]*?)\n*Item.*?1B
(?i)(?<!\d)Item.*?1A.*?Risk.*?Factors
匹配到風險因素結束。\n*
根據需要匹配盡可能多的換行符,直到我們到達下一段。([\s\S]*?)
捕獲任何內容,跨越任意數量的行(惰性)。\n*
根據需要匹配盡可能多的換行符,直到我們到達下一段。Item.*?1B
匹配其余內容。(這與最后的不匹配.
,您的意思是這樣嗎?如果是,請添加\.
到最后)。
添加回答
舉報
0/150
提交
取消