求一正则表达式 小弟不会正则表达式,但现在需用到特向各位大哥求一好的获取链接地址的正则表达式,如……<a href="http://community.csdn.net/">,要得到http://community.csdn.net/感激不尽!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果是取一个,这样stirng yourStr = ..............;string resultStr = "";Match m = Regex.Match(yourStr, @"<a\s[^>]*href=(['""]?)(?<url>[^'""\s]*)\1?[^>]*>", RegexOptions.IgnoreCase);if (m.Success){ resultStr = m.Groups["url"].Value;} string url = "……<a href="http://community.csdn.net/">";url = Regex.Replace(url, @".*<a\s+href=\"(?<url>http://[^\"]*)\">.*", "${url}", RegexOptions.IgnoreCase | RegexOptions.Compiled); 如果同时取多个,这样string yourStr = ...............;MatchCollection mc = Regex.Matches(yourStr, @"<a\s[^>]*href=(['""]?)(?<url>[^'""\s]*)\1?[^>]*>", RegexOptions.IgnoreCase);foreach (Match m in mc){ richTextBox2.Text += m.Groups["url"].Value + "\n";} <a.*?href=['""]*(?<url>[^'"" >]*?)['"" >]我用的这个.----------------------- CSDN 论坛助手 http://china-csdn.cn <a\s[^>]*href\s*=\s*(['"]?)(?<url>[^'"\s>]*)[^>]*>补充一下 <a\s[^>]*href=(['""]?)(?<url>[^'""\s]*)\1?[^>]*> public string SniffwebCode(string code, string wordsBegin, string wordsEnd) { string NewsTitle=""; Regex regex1 = new Regex("" + wordsBegin + @"(?<title>[\s\S]+?)" + wordsEnd + "", RegexOptions.Compiled | RegexOptions.IgnoreCase); for (Match match1 = regex1.Match(code); match1.Success; match1 = match1.NextMatch()) { NewsTitle = match1.Groups["title"].ToString(); } return NewsTitle; }在本题中 wordsBegin 为: <a href=" wordsEnd 为: "> 此正则表达式可以匹配任何 在wordbegin和wordend中的内容 如何获得一个List<double>中的最大值 求一个学习模板的网址 怎么用C#做文件的上传下载, dataview.RowFilter问题 急!!!需要你的帮助!! 多少个不眠之夜,自己的混淆器终于出炉,发布出来供大家使用,高兴散分! 鼠标滚轮的功能如何在程序中实现? 如何保证录入数据的唯一性? 剪刀石头布问题 掀起学习C#的新高潮 关于制作安装程序的问题!************(在线等候)当场给分!******************** c#的抽象类里面可以不包含抽象和虚的成员?? 窗体界面XP风格
string resultStr = "";
Match m = Regex.Match(yourStr, @"<a\s[^>]*href=(['""]?)(?<url>[^'""\s]*)\1?[^>]*>", RegexOptions.IgnoreCase);
if (m.Success)
{
resultStr = m.Groups["url"].Value;
}
url = Regex.Replace(url, @".*<a\s+href=\"(?<url>http://[^\"]*)\">.*", "${url}", RegexOptions.IgnoreCase | RegexOptions.Compiled);
MatchCollection mc = Regex.Matches(yourStr, @"<a\s[^>]*href=(['""]?)(?<url>[^'""\s]*)\1?[^>]*>", RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups["url"].Value + "\n";
}
-----------------------
CSDN 论坛助手
http://china-csdn.cn
补充一下
{
string NewsTitle="";
Regex regex1 = new Regex("" + wordsBegin + @"(?<title>[\s\S]+?)" + wordsEnd + "", RegexOptions.Compiled | RegexOptions.IgnoreCase);
for (Match match1 = regex1.Match(code); match1.Success; match1 = match1.NextMatch())
{
NewsTitle = match1.Groups["title"].ToString();
}
return NewsTitle;
}在本题中 wordsBegin 为: <a href=" wordsEnd 为: ">