求一个正则表达式.....

huhailong520 2011-03-17 07:12:32
172.18.11.17 - - [21/Dec/2010:00:01:27 +0800] "GET /2007-11-20/1195434904191.html HTTP/1.0" 200 13776 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)"

172.18.11.17 - - [21/Dec/2010:00:03:51 +0800] "GET /investment/english.jsp HTTP/1.0" 200 52042 "http://www.investment.gov.cn/investment/english.jsp" "Mozilla/4.0"

172.18.11.17 - - [21/Dec/2010:00:09:19 +0800] "GET /investment/resource/images/IM-CN-flash-2.swf HTTP/1.0" 304 - "http://www.investment.gov.cn/investment/pages/en/information.do?method=listen&menuId=1129914278594" "Mozilla/4.0 (compatible;)"

这样一个字符串,想找到里面有HTTP。。。。的且有.jsp,.do,.html,这样正则怎么写啊?
...全文
7961 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
huhailong520 2011-03-17
  • 打赏
  • 举报
回复
http://misc.yahoo.com.cn/help.html
http://www.investment.gov.cn/investment/english.jsp
http://www.investment.gov.cn/investment/pages/en/information.do
http://www.investment.gov.cn/investment/pages/en/information.aspx

怎么判断后缀名是.jsp,.do,.html呢 正则
huhailong520 2011-03-17
  • 打赏
  • 举报
回复
http://misc.yahoo.com.cn/help.html
http://www.investment.gov.cn/investment/english.jsp
http://www.investment.gov.cn/investment/pages/en/information.do
怎么取得后缀名呢?
huhailong520 2011-03-17
  • 打赏
  • 举报
回复
只要有HTTP的且HTTP连接中有.jsp,.do,.html http前面有一串字符,他后面也有,这样匹配的
q107770540 2011-03-17
  • 打赏
  • 举报
回复
void Main()
{
var list = new string[] { @"172.18.11.17 - - [21/Dec/2010:00:01:27 +0800] ""GET /2007-11-20/1195434904191.html HTTP/1.0"" 200 13776 ""-"" ""Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)""",

@"172.18.11.17 - - [21/Dec/2010:00:03:51 +0800] ""GET /investment/english.jsp HTTP/1.0"" 200 52042 ""http://www.investment.gov.cn/investment/english.jsp"" ""Mozilla/4.0""",

@"172.18.11.17 - - [21/Dec/2010:00:09:19 +0800] ""GET /investment/resource/images/IM-CN-flash-2.swf HTTP/1.0"" 304 - ""http://www.investment.gov.cn/investment/pages/en/information.do?method=listen&menuId=1129914278594"" ""Mozilla/4.0 (compatible;)"""};

Regex reg=new Regex(@"[^""]*?""GET[^\.]*\.(?:html|jsp|do)\sHTTP.*");
foreach(var s in list)
{
Console.WriteLine(string.Format("{0}\t验证结果:{1}通过",s,reg.IsMatch(s)?"":"不"));
}
}

/*
172.18.11.17 - - [21/Dec/2010:00:01:27 +0800] "GET /2007-11-20/1195434904191.html HTTP/1.0" 200 13776 "-" "Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)" 验证结果:通过
172.18.11.17 - - [21/Dec/2010:00:03:51 +0800] "GET /investment/english.jsp HTTP/1.0" 200 52042 "http://www.investment.gov.cn/investment/english.jsp" "Mozilla/4.0" 验证结果:通过
172.18.11.17 - - [21/Dec/2010:00:09:19 +0800] "GET /investment/resource/images/IM-CN-flash-2.swf HTTP/1.0" 304 - "http://www.investment.gov.cn/investment/pages/en/information.do?method=listen&menuId=1129914278594" "Mozilla/4.0 (compatible;)" 验证结果:不通过
*/
huhailong520 2011-03-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 q107770540 的回复:]
"GET[^\.]*\.(?:html|jsp|do)\sHTTP

Regex.IsMatch()
[/Quote]

你是正确的,我没有表达清除啊!不仅要有http的还要判断后缀的!
huangwenquan123 2011-03-17
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 q107770540 的回复:]
"GET[^\.]*\.(?:html|jsp|do)\sHTTP

Regex.IsMatch()
[/Quote]我还以为是要链接后缀名有那些的
huangwenquan123 2011-03-17
  • 打赏
  • 举报
回复
            string str="172.18.11.17 - - [21/Dec/2010:00:01:27 +0800] \"GET /2007-11-20/1195434904191.html HTTP/1.0\" 200 13776 \"-\" \"Mozilla/5.0 (compatible; Yahoo! Slurp China; http://misc.yahoo.com.cn/help.html)\""

+"172.18.11.17 - - [21/Dec/2010:00:03:51 +0800] \"GET /investment/english.jsp HTTP/1.0\" 200 52042 \"http://www.investment.gov.cn/investment/english.jsp\" \"Mozilla/4.0\""

+"172.18.11.17 - - [21/Dec/2010:00:09:19 +0800] \"GET /investment/resource/images/IM-CN-flash-2.swf HTTP/1.0\" 304 - \"http://www.investment.gov.cn/investment/pages/en/information.do?method=listen&menuId=1129914278594\" \"Mozilla/4.0 (compatible;)\"";
Regex reg = new Regex(@"http://[^"")?]*");
foreach (Match m in reg.Matches(str))
{
Response.Write(m.Value + "<br/>");
}
/*
http://misc.yahoo.com.cn/help.html
http://www.investment.gov.cn/investment/english.jsp
http://www.investment.gov.cn/investment/pages/en/information.do
*/
q107770540 2011-03-17
  • 打赏
  • 举报
回复
"GET[^\.]*\.(?:html|jsp|do)\sHTTP

Regex.IsMatch()

62,041

社区成员

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

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

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

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