public void ShowStructure()
{
//要匹配的字符串
string text = "\r\n \r\n
\r\n \r\n";
//正则表达式
string pattern = @"]*value[=\s\"\']+([^\"\']*)[\"\']?";
//使用RegexOptions.IgnoreCase枚举值表示不区分大小写
Regex r = new Regex(pattern, RegexOptions.IgnoreCase);
//使用正则表达式匹配字符串,仅返回一次匹配结果
Match m = r.Match(text);
while (m.Success)
{
//显示匹配开始处的索引值和匹配到的值
System.Console.WriteLine("Match=[" + m + "]");
CaptureCollection cc = m.Captures;
foreach (Capture c in cc)
{
Console.WriteLine("\tCapture=[" + c + "]");
}
for (int i = 0; i < m.Groups.Count; i++)
{
Group group = m.Groups[i];
System.Console.WriteLine("\t\tGroups[{0}]=[{1}]", i, group);
for (int j = 0; j < group.Captures.Count; j++)
{
Capture capture = group.Captures[j];
Console.WriteLine("\t\t\tCaptures[{0}]=[{1}]", j, capture);
}
}
//进行下一次匹配.
m = m.NextMatch();
}
}回答2:
value为命名组
教程如下
http://www.jb51.net/article/360.htm