使用正则表达式捕获具有特殊字符的字符串

Use regex to capture a string that has special characters

我正在尝试使用正则表达式来解析字符串并提取所需的数据。这是我的字符串:

Validate control value for ELEMENT - VerifyFirstRowSearchNotes as ~Creating Stat Reserve: ~IP: Claimant Driver; IP Role(s): Owner, Driver~Exposure

我正在尝试使用以下正则表达式模式捕获数据。我对 "as" 后面的数据特别感兴趣。但是,我只能捕获下面的控制值,无法在 "as" 之后提取任何内容并将其分配给字段组:

string actionpattern = @"Validate control value for ELEMENT - (?<control>.*?)as (?<fields>.*?)";
var regex = new Regex(actionpattern, RegexOptions.IgnoreCase);
var match = regex.Match({above string});

让我知道我做错了什么。我是正则表达式的新手,正在学习中。

如果你去掉这部分的问号(?<fields>.*?)你会让它变得贪婪并匹配后面的所有内容作为(?<fields>.*)

您的正则表达式如下所示:

Validate control value for ELEMENT - (?<control>.*?)as (?<fields>.*)