题目1:
href="http://aaaa.bbbb.cccc.com/"
其中,aaaa是可变的(英文或数字或这两者组合),bbbb.cccc.com是不变的。
求匹配该段字符的正则表达式,并得到http://aaaa.bbbb.cccc.com/题目2:
href="http://aaaa.bbb.com/ccc/ddd/eeee.html"
其中,eeee是可变的(英文或数字或这两者组合),http://aaaa.bbb.com/ccc/ddd/是不变的
求匹配该段字符的正则表达式,并得到http://aaaa.bbb.com/ccc/ddd/eeee.html
补充:
href="http://aaaa.bbbb.cccc.com/" href="http://aaaa.bbb.com/ccc/ddd/eeee.html"链接里只能为该链接。 形如href="http://aaaa.bbbb.cccc.com/xxxx"的就不匹配了,注意""号

解决方案 »

  1.   


    你确定试过我给你写的了?1. http://[A-Za-z0-9]+\.b{4}\.c{4}\.com/2. http://a{4}\.b{3}\.com/c{3}/d{3}/[A-Za-z0-9]+\.html
      

  2.   

    试过, 但不满足链接里只能为该链接。 形如href="http://aaaa.bbbb.cccc.com/xxxx"的就不匹配了,注意""号这个要求呀
      

  3.   


    第二条。。href="http://aaaa.bbbb.cccc.com/xxxx"本来就不会匹配啊。
      

  4.   

    1.   (?<=href=\")http://[A-Za-z0-9]+\.b{4}\.c{4}\.com/(?=\")2.   (?<=href=\")http://a{4}\.b{3,4}\.com/c{3}/d{3}/[A-Za-z0-9]+\.html(?=\")
      

  5.   

    1. ?<=href=\")http://[A-Za-z0-9]+\.b{4}\.c{4}\.com/(?=\"2. ?<=href=\")http://a{4}\.b{3,4}\.com/c{3}/d{3}/[A-Za-z0-9]+\.html(?=\"这两个正则放进去就出错了
      

  6.   

    题目1:
    href="http://aaaa.bbbb.cccc.com/"
    RegEx: (?<=")http://(?<host>[a-zA-z0-9]+).bbbb.cccc.com/(?=")
                    string sampleText = @"href=""http://aaaa.bbbb.cccc.com/""";
                    Regex regex = new Regex("(?<=\")http://(?<host>[a-zA-z0-9]+).bbbb.cccc.com/(?=\")");
                    Match match = regex.Match(sampleText);
                    while (match.Success)
                    {
                        System.Diagnostics.Debug.WriteLine("href: " + match.Value);
                        System.Diagnostics.Debug.WriteLine("host: " + match.Groups["host"].Value);
                        match = match.NextMatch();
                    }
    题目2:
    href="http://aaaa.bbb.com/ccc/ddd/eeee.html"RegEx: (?<=")http://aaaa.bbb.com/ccc/ddd/(?<name>[a-zA-Z0-9]+).html(?=")
                    string sampleText = @"href=""http://aaaa.bbb.com/ccc/ddd/eeee.html""";
                    Regex regex = new Regex("(?<=\")http://aaaa.bbb.com/ccc/ddd/(?<name>[a-zA-Z0-9]+).html(?=\")");
                    Match match = regex.Match(sampleText);
                    while (match.Success)
                    {
                        System.Diagnostics.Debug.WriteLine("href: " + match.Value);
                        System.Diagnostics.Debug.WriteLine("name: " + match.Groups["name"].Value);
                        match = match.NextMatch();
                    }
      

  7.   

    1. (?<=href=\")http://[A-Za-z0-9]+\.b{4}\.c{4}\.com/(?=\")2. (?<=href=\")http://a{4}\.b{3,4}\.com/c{3}/d{3}/[A-Za-z0-9]+\.html(?=\")foreach (Match m in Regex.Matches(listSrouce, "(?<=href=\")http://[A-Za-z0-9]+\.b{4}\.c{4}\.com/(?=\")"))//第1种地址
                        {
                           m.Value;  //不是这样得到吗?????}
      

  8.   


    哎。。我帮你写出来吧。。
      string str = "href=\"http://aaaa.bbbb.cccc.com/\"";
                Regex re = new Regex("(?<=href=\\\")http://[A-Za-z0-9]+\\.b{4}\\.c{4}\\.com/(?=\\\")", RegexOptions.None);
                MatchCollection mc = re.Matches(str);
                foreach (Match ma in mc)
                {
                    Response.Write(ma.Value);
                }
      

  9.   


    这是第二个。。
    string str = "href=\"http://aaaa.bbb.com/ccc/ddd/eeee.html\"";
                Regex re = new Regex("(?<=href=\\\")http://a{4}\\.b{3,4}\\.com/c{3}/d{3}/[A-Za-z0-9]+\\.html(?=\\\")", RegexOptions.None);
                MatchCollection mc = re.Matches(str);
                foreach (Match ma in mc)
                {
                    Response.Write(ma.Value);
                }
      

  10.   

    调试了一下,应该是下面这样才对题目1:
    href="http://aaaa.bbbb.cccc.com/"RegEx: (?<=")http://(?<host>[a-zA-z0-9]+)\.bbbb\.cccc\.com/(?=")
                    string sampleText = @"href=""http://aaaa.bbb.com/ccc/ddd/eeee.html""";
                    Regex regex = new Regex(@"(?<="")http://aaaa\.bbb\.com/ccc/ddd/(?<name>[a-zA-Z0-9]+)\.html(?="")");
                    Match match = regex.Match(sampleText);
                    while (match.Success)
                    {
                        System.Diagnostics.Debug.WriteLine("href: " + match.Value);
                        System.Diagnostics.Debug.WriteLine("name: " + match.Groups["name"].Value);
                        match = match.NextMatch();
                    }
    题目2:
    href="http://aaaa.bbb.com/ccc/ddd/eeee.html"RegEx: (?<=")http://aaaa\.bbb\.com/ccc/ddd/(?<name>[a-zA-Z0-9]+)\.html(?=")
                    string sampleText = @"href=""http://aaaa.bbb.com/ccc/ddd/eeee.html""";
                    Regex regex = new Regex(@"(?<="")http://aaaa\.bbb\.com/ccc/ddd/(?<name>[a-zA-Z0-9]+)\.html(?="")");
                    Match match = regex.Match(sampleText);
                    while (match.Success)
                    {
                        System.Diagnostics.Debug.WriteLine("href: " + match.Value);
                        System.Diagnostics.Debug.WriteLine("name: " + match.Groups["name"].Value);
                        match = match.NextMatch();
                    }