当前位置:编程学习 > C#/ASP.NET >>

求一正则表达式

我有一字符串:<a class=page_numb href=http://www.tianya.cn/publicforum/content/motss/1/202489.shtml>9</a> <a class=page_numb href=http://www.tianya.cn/publicforum/content/motss/1/203089.shtml>10</a> <a  href=http://www.tiana.cn/pubicforum/content/moss/1/1910.shtml><font color=#246cae>下一页</a> <a  href=http://www.tinya.cn/pubicforum/conent/moss/1/2063.shtml><font color=#246cae>末页</font></a> <a   href=http://www.tiaya.cn/publiforum/conent/mss/1/208463.shtml><font color=#246cae>


只要求出带“下一页”的链接,即以上求出http://www.tiana.cn/pubicforum/content/moss/1/1910.shtml

我用以下正则却不能提出地址,请问我怎么写正则才对?
m2 = Regex.Matches(ostr, "<a  href.*?>.*?[下一页].*?</a>"); --------------------编程问答-------------------- string  webDocContent="":
string strPattern=@"a[\s]+href=(?<Link>[^\s>]+)[^>]*>(?<Text>[^<]*)</a>";
            MatchCollection Matches=Regex.Matches(webDocContent,strPattern,RegexOptions.IgnoreCase|RegexOptions.Compiled);
            foreach(Match NextMatch in Matches)
            {
                string URL=NextMatch.Groups["Link"].Value.ToString().Trim();
                string URLText=NextMatch.Groups["Text"].Value.ToString().Trim();
                Response.Write(URL);
                Response.Write(URLText);
            }
判断URLText内容是否为下一页 --------------------编程问答-------------------- 以上帮助不了我。。继续求助 --------------------编程问答-------------------- try...

Regex reg = new Regex(@"(?is)<a(?:(?!href=).)*href=(['""]?)(?<url>[^""'\s>]*)\1[^>]*>(?:(?!下一页|</?a\b).)*下一页(?:(?!下一页|</?a\b).)*</a>");
Match m = reg.Match(yourStr);
if (m.Success)
{
    richTextBox2.Text = m.Groups["url"].Value;
}
--------------------编程问答-------------------- 过客的正则就是强大   没办法抢分了 --------------------编程问答-------------------- 帮顶!! --------------------编程问答--------------------
引用 4 楼 wangjun8868 的回复:
过客的正则就是强大  没办法抢分了


悄悄的说,我白天通常上不了网的

不过在论坛里有人抢分才有乐趣,我当年就是这样抢过来的,尤其是虎口夺食,会很有成就感
07年人气高,抢分比较激烈,强迫自己必须在几分钟内给出正确的答案,否则分就被抢走了,这也是提升技能一个很好的方式 --------------------编程问答--------------------
引用 6 楼 lxcnn 的回复:
引用 4 楼 wangjun8868 的回复:
过客的正则就是强大  没办法抢分了


悄悄的说,我白天通常上不了网的

不过在论坛里有人抢分才有乐趣,我当年就是这样抢过来的,尤其是虎口夺食,会很有成就感
07年人气高,抢分比较激烈,强迫自己必须在几分钟内给出正确的答案,否则分就被抢走了,这也是提升技能一个很好的方式


的确很佩服你的正则 --------------------编程问答-------------------- 3楼太强了 --------------------编程问答-------------------- 看不懂  呵呵  新手中的新手 --------------------编程问答-------------------- m2 = Regex.Matches(@"a[\s]+href=(? <Link>[^\s>]+)[^>]*>(? <Text>[^ <]*) </a>");  --------------------编程问答-------------------- mark
学习
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,