我这里有多个
<ul name=""goods"" id="abc">
..........
<ul>如何获取ul中的.........如下是我的代码可是不好用。
MatchCollection mc = Regex.Matches(strBody, <ul name=""goods"" (.*?)<ul>", RegexOptions.IgnoreCase);

解决方案 »

  1.   


    MatchCollection mc = Regex.Matches(strBody, @"<ul\s*name=""goods""[^<>]*>(?<need>[^<>]*)<ul>", RegexOptions.IgnoreCase);
    Groups["need"]
      

  2.   

    mc获得的数量还是零个啊未获取到~后面<ul>改为</ul>也不好用
      

  3.   

    using System;
    using System.Text;
    using System.Text.RegularExpressions;
    class Test
    {
        static void Main()
        {
            string str = @"<ul name=""goods"" id=""abc"">
    ..........
    <ul> ";
            MatchCollection mc = Regex.Matches(str, @"<ul[\s\S]*?>([\s\S]*?)<ul", RegexOptions.IgnoreCase);//由于有换行。所以不能使用.*?,除非你先过滤掉\n\r
            foreach (Match m in mc)
            {
                Console.WriteLine(m.Groups[1].Value.Trim());
            }
            Console.ReadKey();
        }
    }
      

  4.   

    优化一下得到下面:
                string str = "";
                string strBody = @"<ul name=""goods"" >.......... <ul> sd<ul name=""goods"" >...fff.... <ul>79";
                MatchCollection m1 = Regex.Matches(strBody, @"<ul\s*name=""goods""[^<>]*>(?<need>[^<>]*)<ul>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                foreach (Match m in m1)
                {
                        str += m.Groups["need"].Value+"<br>";
                }
                Response.Write(str);输出结果:
    .......... 
    ...fff....  
      

  5.   

    MatchCollection m1 = Regex.Matches(strBody, @"<ul\s*name=""goods""[^>]*>(?<need>[^<]*)?<ul>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
    这样更简约些 后面的参数RegexOptions.Singleline保证html换行时也能正确匹配到
      

  6.   

    这个讲得很全面
    http://www.jb51.net/article/3349.htm
      

  7.   

    http://unibetter.com/deerchao/zhengzhe-biaodashi-jiaocheng-se.htm如果你看完后一无所获.那么我从此不会再回答你任何的问题!