簡體   English   中英

正則表達式提取字符串之間的數據

[英]Regex to extract data in between string

我試過下面的 ff 正則表達式,但它似乎不起作用。 我想提取 F. Prepaids 和 G. Initial Escrow Payment 之間的數據,並得到下面的 ff 示例結果。 謝謝。

#我的正則表達式

(?<=F. Prepaids)[\S\s]*?(?= G. Initial Escrow Payment)

#細繩

F. Prepaids $887.01
01 Homeowner's Insurance Premium ( 12 mo.) toAmerican Family  $893.00
Insura
02 Mortgage Insurance Premium (     mo.)
03 Prepaid Interest ($5.99 per day from 10/02/2020 to 10/01/2020) -$5.99
04 Property Taxes (     mo.)
05
06
07
08
G. Initial Escrow Payment at Closing $3,776.11

如果我得到了介於兩者之間的數據,我還需要一個正則表達式來獲得 ff 結果,其中其他數據包含基於上述字符串的新行。

Homeowner's Insurance Premium ( 12 mo.) to American Family Insura
Mortgage Insurance Premium ( mo.)
Prepaid Interest ($5.99 per day from 10/02/2020 to 10/01/2020)
Property Taxes (     mo.)

對這個有什么想法嗎? 謝謝。

您可以使用

(?m)(?<=F\. Prepaids[\s\S]*?^\d+ )[^\r\n]+(?:\r?\n[^\n\d][^\r\n]*)?(?=[\s\S]*?\nG\. Initial Escrow Payment)

查看正則表達式演示

細節

  • (?m) - 多行模式開啟
  • (?<=F\\. Prepaids[\\s\\S]*?^\\d+ ) - 匹配緊跟在F. Prepaids之前的位置,然后是盡可能少的零個或多個字符,然后是開頭的 1+ 個數字一行,然后一個空格
  • [^\\r\\n]+ - 除了 CR 和 LF 之外的任何一個或多個字符和
  • (?:\\r?\\n[^\\n\\d][^\\r\\n]*)* - 零個或多個 CRLF 或 LF 結尾序列,任何非數字和非換行符,然后是任何零或除了換行符和回車符之外的更多字符
  • (?=[\\s\\S]*?\\nG\\. Initial Escrow Payment) - 當前位置必須跟
    • [\\s\\S]*? - 盡可能少的零個或多個字符
    • \\n - 換行
    • G\\. Initial Escrow Payment G\\. Initial Escrow Payment - G. Initial Escrow Payment文本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM