62,041
社区成员
发帖
与我相关
我的任务
分享
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;)" 验证结果:不通过
*/
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
*/