如何将多行文本复制到特定事件

时间:2017-11-04 19:53:31

标签: regex

我有大行的文本文件。每个“参考”都有您的数据和任何文本。 我如何只获得所有行“参考CI-PERSONA”?

Date: 28/10/2017
Reference: CI-Auto
1. any text any text

2. any text any text

Date: 29/10/2017
Reference: CI-Persona
1. any text any text


Date: 29/10/2017
Reference: CI-Persona
1. any text any text

2. any text any text

Date: 29/10/2017
Reference: CI-Civil
1. any text any text

2. any text any text

3. any text any text

Date: 29/10/2017
Reference: CI-Persona
1. any text any text

预期结果是:

Date: 29/10/2017
Reference: CI-Persona
1. any text any text


Date: 29/10/2017
Reference: CI-Persona
1. any text any text

2. any text any text

Date: 29/10/2017
Reference: CI-Persona
1. any text any text

有人可以帮帮我吗?我正在使用C#。

1 个答案:

答案 0 :(得分:0)

不太好,但确实有效:

string pattern = @"Date:\s\d{1,2}\/\d{1,2}\/\d{4}(\n|\r|\r\n)Reference:.CI-Persona(?:(?!\s^Date).)+";
MatchCollection matches = Regex.Matches(input, pattern, RegexOptions.Multiline | RegexOptions.Singleline);