求一个正则表达式

zftow110 2008-07-02 06:41:01
Regex re = new Regex(@"http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?", RegexOptions.IgnoreCase);

这个正则表达式能够把所有HTTP过滤出来,但象.JS.CSS.GIF.JPG这些都出来了,
现在表达式怎么写才能把这些都过滤掉,不显示!
感谢大家,有点急!!!

或者谁有更好的表达试,也可以,谢谢!
...全文
138 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
家鸣 2008-07-03
  • 打赏
  • 举报
回复
try this:

string s2 = "http://sports.sina.com.cn/chinaa/changchun/abc.js http://abc.ddd.cn/ty/21.jpg http://sports.sina.com.cn/z/afc_cl2008/aaaa.css ";
s2 += "http://abc.ddd.cn/009.gif http://abc.ddd.cn/ty/21.html http://abc.ddd.cn/ty/21.aspx?abc=ddd&name=jason";
Regex re = new Regex(@"(?>http://([\w-_]+\.)+[\w-_]+[\w-_%:/]*\.)(?!gif|jpg|css|js)([\w-_:./?%&=]*)?", RegexOptions.IgnoreCase);
MatchCollection matchesFound = re.Matches(s2);
foreach (Match match in matchesFound)
{
Console.WriteLine(match.Value);
}
zftow110 2008-07-03
  • 打赏
  • 举报
回复
我还没那么厉害吧,只是做一些内容的抓取!
deknight 2008-07-03
  • 打赏
  • 举报
回复
看来是要做搜索引擎
root_ 2008-07-03
  • 打赏
  • 举报
回复
在适当位置加(?!jpg|gif|js|css)或(?<!jpg|gif|js|css)可以解决你目前提出的问题,但并不是治本之道,还是说下你想要得到什么样的链接,用<a...>标签之类的限定一下比较好
zftow110 2008-07-03
  • 打赏
  • 举报
回复
顶一下,希望老大们出来帮帮忙!!
zftow110 2008-07-03
  • 打赏
  • 举报
回复
贴出函数,用来得到所有http连接!
public string HttpUR_Filtrate(string Http_String,string auto_string)
{
string URString = "";

ArrayList my_list = new ArrayList();
Regex re = new Regex(@"http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?", RegexOptions.IgnoreCase);
MatchCollection mc = re.Matches(Http_String);

try
{
for (int i = 0; i <= mc.Count - 1; i++)
{
bool _foo = false;
string name = mc[i].ToString();
foreach (string list in my_list)
{
if (name == list)
{
_foo = true;
break;
}
}
if (!_foo)
{
URString += name + "<BR>";
}
}
}
catch
{
URString = auto_string;
}

return URString;

}



得到的结果是所有包括图片连接GIF,JPG等,和JS,CSS等连接都一起得到了,现在不要GIF,JPG,JS,CSS等


现在得到结果象这样
http://i2.sinaimg.cn/ty/up/2008-07-03/U2249P6T64D48690F1091DT20080703003541.jpg
http://sports.sina.com.cn/j/08zc12/
http://www.shidefc.com/
http://sports.sina.com.cn/chinaa/shide/
http://i1.sinaimg.cn/ty/up/2008-07-03/U2249P6T64D48690F1322DT20080703003821.jpg
http://sports.sina.com.cn/j/2008-07-02/21233761078.shtml
http://sports.sina.com.cn/j/2008-07-02/23213761184.shtml
http://www.lnts.com.cn/
http://sports.sina.com.cn/chinaa/luneng/
http://i0.sinaimg.cn/ty/up/2008-07-03/U2249P6T64D48690F1323DT20080703003821.jpg
http://sports.sina.com.cn/j/2008-07-02/21283761080.shtml
http://sports.sina.com.cn/j/2008-07-02/22123761124.shtml
http://www.yataifc.com/
http://www.sufc.com.cn/
http://sports.sina.com.cn/chinaa/changchun/
http://i1.sinaimg.cn/ty/up/2008-07-03/U2249P6T64D48690F1324DT20080703003821.jpg
http://sports.sina.com.cn/j/2008-07-02/21303761081.shtml
http://sports.sina.com.cn/j/2008-07-02/22393761154.shtml
http://sports.sina.com.cn/z/afc_cl2008/
http://sports.sina.com.cn/chinaa/
http://i3.sinaimg.cn/ty/08index/images/sports_home_lmy_009.gif
http://sports.sina.com.cn/j/2008-07-03/00563761266.shtml
http://sports.sina.com.cn/j/2008-07-03/00263761243.shtml
http://sports.sina.com.cn/j/2008-07-03/00243761241.shtml
liuyun1987 2008-07-03
  • 打赏
  • 举报
回复
建议LZ先下找30分钟正则的教程看看。看了你自己肯定能写出来。。不难。
root_ 2008-07-02
  • 打赏
  • 举报
回复
需求不明确,具体问题具体分析

说明规律,或给出实例和对应的结果

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧