div[\w\W]+strong\>([^\<]+)\<[\w\W]+date\"\>([^\<])+\<[\w\W]+nianhualv\"\>([^\<]+)\<[\w\W]+qiri\"\>([^\<]+)\<[\w\W]+\/div\>
没测试,不能确定正确性

解决方案 »

  1.   

    正则匹配的时候,应该先匹配:<div class="con">    xxxx <div> 这段内容吧。然后再匹配里面的值。
      

  2.   


    string pattern = ">([^< ].*?)<";
    MatchCollection mc = Regex.Matches(content, pattern);
    foreach (Match m in mc)
    {
    string val = m.Groups[m.Groups.Count - 1].ToString();
    }
      

  3.   

    或者直接把前后的尖角号去掉,string pattern = "(?<=\\>)([^< ].*?)(?=\\<)", 然后直接迭代mc,去m的值就ok了
      

  4.   


            static void Main(string[] args)
            {
                string regexStr = ">([^< ].*?)<";
                string str = @"<div class=""con"">                    <p><strong>值1</strong><span class=""date"">值2</span></p>                      <p><em class=""nianhualv"">值3</em><span class=""qiri"">值4</span></p>                    <p><a class=""doit"" href=""http://www.baidu.com/fud/chase.htm"" target=""_blank"">值5</a></p>                </div>";
                Console.WriteLine(str);
                List<string> res = Search(str, regexStr);
                foreach (string a in res)
                {
                    Console.WriteLine(a);
                }
                Console.ReadKey();
            }        {
                List<string> res = new List<string>();
                Regex r = new Regex(regexStr, RegexOptions.None);
                Match mc = r.Match(str);
                while (mc.Success)
                {
                    Group g = mc.Groups[1];
                    res.Add(g.Value);
                    mc = mc.NextMatch();
                }
                return res;
            }
      

  5.   

    前面是使用办法后面是方法:
    public static List<string> Search(string str, string regexStr)
      

  6.   

    写了个通用的
    ^(?:(?'open'<)[^<>]+(?'-open'>)(?'cont'[^<>]*))*(?(open)(?!))$
    测试通过:
    要求标签一定要有开始和结尾:
    <div></div>       ok
    </div>            no