【发布时间】:2018-01-06 05:36:35
【问题描述】:
问题
我有一个很长的非结构化文本,我需要从中提取多组文本。
我有一个理想的开始和结束。
这是一个非结构化文本被截断的例子:
more useless gibberish at the begininng...
separated by new lines...
START Fund Class Fund Number Fund Currency
XYZ XYZ XYZ USD
bunch of text with lots of newlines in between... Closing 11.11 1,111.11 111,111.11
more useless gibberish between the groups...
separated by new lines...
START Fund Class Fund Number Fund Currency
XYZ XYZ XYZ USD
The word START appears in the middle sometimes multiple times, but it's fine bunch of text with lots of newlines in between... Closing 22.22 2,222.22 222,222.22
more useless gibberish at the end...
separated by new lines...
我尝试过的
在上面的示例中,我想提取出位于START 和Closing 之间的两组文本
我已经使用正则表达式成功地做到了
/(?<=START)(?s)(.*?)(?=Closing)/g
这是https://regex101.com/r/vo7CLx/1/的结果
怎么了?
不幸的是,我还需要提取包含Closing字符串的行尾。
如果您从regex101 链接中注意到,第一场比赛中有一个Closing 11.11 1,111.11 111,111.11。在第二场比赛中还有Closing 22.22 2,222.22 222,222.22。
哪个正则表达式不匹配。
有没有办法在单个正则表达式中做到这一点?这样就连带数字的结束标签也包括在内?
【问题讨论】:
-
喜欢this?