我正在尝试创建正则表达式以匹配所有日期,描述和金额。我几乎有它,但是最后一行混乱了,并且匹配30.98而不是-58.00。
如何匹配“ 06/14/18”,“ HECK ORDER00172 DES:FEE ID:1FCG0340 PMT信息:产品(S):30.98 S&H:22.91 GA税:4.11”,“-58.00”?连同所有其他交易行?
这是我想出的表达式'/([0-9]{2}/[0-9]{2}/[0-9]{2})\s+(.*?)\s+ ([0-9 \,-] +。[0-9] {2})/ mis'
在此处查看此示例https://regex101.com/r/uuHcFT/1
06/13/18 CHECKCARD 0612 WAFFLE HOUSE 1554 BUFORD GA 163206888100637 CKCD
5812 XXXXXXXXXXXX7127 XXXX XXXX XXXX 7127
-14.00
06/13/18 CHECKCARD 0612 SQU*SQ *BRAVO MEX Buford GA 550191566794 CKCD
5812 XXXXXXXXXXXX7127 XXXX XXXX XXXX 7127
-12.56
Date Check # Amount Date Check # Amount
06/05/18 1293 -1,289.00 06/14/18 1309 -500.72
Date Transaction description Amount
06/01/18 FEE -29.95
06/14/18 CHECK ORDER00172 DES:FEE ID:1FCG0340
PMT INFO: PRODUCT(S): 30.98 S&H: 22.91 GA TAX: 4.11
-58.00
Total service fees -$87.95
我希望表达式匹配以下内容:
1) "06/13/18", "CHECKCARD 0612 WAFFLE HOUSE 1554 BUFORD GA 163206888100637 CKCD 5812 XXXXXXXXXXXX7127 XXXX XXXX XXXX 7127", "-14.00"
2) "06/13/18", "CHECKCARD 0612 SQU*SQ *BRAVO MEX Buford GA 550191566794 CKCD 5812 XXXXXXXXXXXX7127 XXXX XXXX XXXX 7127", "-12.56"
3) "06/05/18", "1293", "-1,289.00"
4) "06/14/18", "1309", "-500.72"
5) "06/01/18", "FEE", "-29.95"
6) "06/14/18", "CHECK ORDER00172 DES:FEE ID:1FCG0340 PMT INFO: PRODUCT(S): 30.98 S&H: 22.91 GA TAX: 4.11", "-58.00"
答案 0 :(得分:1)
一种可能性是要求最后一个小组是:
(1)后面紧跟一个日期
(2)位于一行的末尾,并且对下一行的第一个字符的负前瞻性只能为数字/小数
还请注意,您可以使用[0-9]
代替\d
:
https://regex101.com/r/uuHcFT/3
(\d{2}\/\d{2}\/\d{2})\s+(.*?)\s+([0-9\,\-]+\.\d{2}) *(?=\d\d\/|$(?!\n-?[\d\.]+$))
^ ---->