简体   繁体   English

正则表达式提取字符串之间的数据

[英]Regex to extract data in between string

Ive tried the ff regex below but it does not seem to work.我试过下面的 ff 正则表达式,但它似乎不起作用。 I wanted to extract data between F. Prepaids and G. Initial Escrow Payment and get the ff sample result below.我想提取 F. Prepaids 和 G. Initial Escrow Payment 之间的数据,并得到下面的 ff 示例结果。 Thanks.谢谢。

#my regex #我的正则表达式

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

#String #细绳

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

If i got the data in between I also want a regex to get the ff result which other data includes new lines based on the strin above.如果我得到了介于两者之间的数据,我还需要一个正则表达式来获得 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.)

Any idea with this one ?对这个有什么想法吗? Thnk you.谢谢。

You may use您可以使用

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

See the regex demo查看正则表达式演示

Details细节

  • (?m) - multiline mode on (?m) - 多行模式开启
  • (?<=F\\. Prepaids[\\s\\S]*?^\\d+ ) - match a location immediately preceded with F. Prepaids , then any zero or more chars as few as possible, then 1+ digits at the start of a line and then a space (?<=F\\. Prepaids[\\s\\S]*?^\\d+ ) - 匹配紧跟在F. Prepaids之前的位置,然后是尽可能少的零个或多个字符,然后是开头的 1+ 个数字一行,然后一个空格
  • [^\\r\\n]+ - any one or more chars other than CR and LF and [^\\r\\n]+ - 除了 CR 和 LF 之外的任何一个或多个字符和
  • (?:\\r?\\n[^\\n\\d][^\\r\\n]*)* - zero or more sequences of CRLF or LF ending, any non-digit and non-newline char and then any zero or more chars other than a newline and carriage return (?:\\r?\\n[^\\n\\d][^\\r\\n]*)* - 零个或多个 CRLF 或 LF 结尾序列,任何非数字和非换行符,然后是任何零或除了换行符和回车符之外的更多字符
  • (?=[\\s\\S]*?\\nG\\. Initial Escrow Payment) - the current location must be followed with (?=[\\s\\S]*?\\nG\\. Initial Escrow Payment) - 当前位置必须跟
    • [\\s\\S]*? - any zero or more chars as few as possible - 尽可能少的零个或多个字符
    • \\n - a newline \\n - 换行
    • G\\. Initial Escrow Payment G\\. Initial Escrow Payment - a G. Initial Escrow Payment text. G\\. Initial Escrow Payment - G. Initial Escrow Payment文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM