C# 返回Html 正则表达式怎么获取 value的值

<bady>
<table>
<tr>
<td>
<input style="background-color:#f2f0e6; " size="12" value="06901894121137">

public void ShowStructure()
{
        //要匹配的字符串
        string text = "<bady>\r\n<table>\r\n<tr>\r\n<td>\r\n<input style="background-color:#f2f0e6; " size="12" value="06901894121137">";
        //正则表达式
        string pattern = @"<input[^>]*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();
        }
}

追问

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-10-14
<input.* value="(?<value>.*)">
value为命名组
教程如下
http://www.jb51.net/article/360.htm
相似回答