c# - 正则表达式 - 查找匹配后的所有行 :

标签 c# regex

给定电子邮件正文中的以下文本:

DO NOT MODIFY SUBJECT LINE ABOVE. Sending this email signifies my Request to Delay distribution of this Product Change Notification (PCN) to 9001 (Qwest). The rationale for this Request to Delay is provided below:

This is the reason I need to capture.

It can be many many lines long.

And go on for a long time

我正在 try catch “...在下面提供:”之后的所有文本。

传递给 BodyRegex 的模式是:

.*provided below:(?<1>.*)

正在执行的代码是:

Regex regex2 = new Regex(BodyRegex, RegexOptions.IgnoreCase | RegexOptions.Multiline);
string note = null;
Match m2 = regex2.Match(body);
if (m2.Success)
{
    note = m2.Groups[1].Value;
}

未找到匹配项。

我需要使用什么匹配模式来捕获“is provided below:”之后的所有文本行?

最佳答案

(?...) 部分是前瞻语法,这不是您想要的。

您可能想试试看后面:

(?<=provided below:)[.|\n|\W|\w]*

我遇到过 .NET 无法按照您期望的方式使用 .* 识别行尾字符的问题,因此出现 or 条件。

关于c# - 正则表达式 - 查找匹配后的所有行 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12628146/

相关文章:

regex - 关联组之前的 Backref

python - 正则表达式匹配特定方法的 javadoc 注释 (python)

c# - 使用 C# 正则表达式排除字符串匹配

c# - Azure 上的 ASP.NET Core 本地化

c# - 为什么 WeakReference.IsAlive 变为假?

c# - 如何在自动生成的 Edmx 文件中设置 Entity Framework CommandTimeout

c# - MySQL C# 文本编码问题

java - java中的UNICODE正则表达式

正则表达式替换 Linux shell 脚本中的密码?

javascript - 在正则表达式中选择字符串后跟空格