繁体   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