首页 新闻 赞助 找找看

请教一个asp 正则

0
悬赏园豆:30 [已解决问题] 解决于 2009-01-04 23:33

我读取了一个网页的源代码,里面有

<td class="p1"> <a onmousedown="return tongji(this.innerHTML,this.href,1)" href="http://119.147.41.16/down?cid=9C8C7592DC5502F64D026FFE5DADD06EBF6E5A4C&t=4&fmt=flv"  target='_blank' </a> </td>

现在我想把http://119.147.41.16/down?cid=9C8C7592DC5502F64D026FFE5DADD06EBF6E5A4C&t=4&fmt=flv

还有[ <strong>情 </strong> <strong>归 </strong> <strong>巴黎 </strong>].Sabrina.(1995).CD1

通过正则表达式 读出来,请问asp的 正则 怎么写?

我的写法  reg = "\<td\s+class\=\""p1\""\>\<a\s+onmousedown\=\s*\"".*?\""\s+href\=\s*\""(.*?)\"".*?\>(.*?)\<\/a\>\<\/d\>"

有问题

请大家指点一二

 

之所以用asp,因为空间只支持asp。

weblogical的主页 weblogical | 初学一级 | 园豆:6
提问于:2008-12-11 15:33
< >
分享
最佳答案
0

这个编辑后内容变来变去的~~你的也变了。我的正则也不见了。。。
看了你的评论才知道原来是这样。。。下面是我写的正则:
<td class="p1">\s*<a\s+.*?\s+href="(.*?)"\s+.*?>\s*(<font.*?)</a>\s*</td>
这个我用RegexBuddy测了。两个group分别是你要的。

你的正则的问题在" <a"和" </a> </td>"中的空格没注意。还有正则不用把所有的都匹配了。只匹配自己关心的那部分就行了。

还是建议你下个RegexBuddy试一试。边写边匹配~想出错都难~~
只有一种情况会出错(?'-name') 出栈不支持~这时候用RegexTester
还有一个更方便的网页形式的(效果跟RegexBuddy差不多,只是功能简单一下)~
http://regexpal.com/
把我的正则和你的html源输进去看看~~

修改的时候先把以前的先复制,粘进来以免丢失内容~~

BB_Coder | 小虾三级 |园豆:797 | 2008-12-11 19:28
其他回答(2)
0

.NET的代码你参考下吧:

 string regexPattern = @"(href\s*=\s*)[""''](?<url>[^''""]+)[""'']";
  //@"<a\s(.*?)+href=(\"")?(.+?)(\"")?\s*(.*?)>(.+?)</a>";
  Regex regex = new Regex(regexPattern, RegexOptions.IgnoreCase);
  Match match = regex.Match(httpSource);
  siteList.Clear();
  while (match.Success)
  {
  string temp = match.Groups["url"].Value;
  if (!temp.EndsWith(".ico") && !temp.EndsWith(".jpg") && !temp.EndsWith(".png") && !temp.EndsWith(".gif") && !temp.EndsWith(".css") && !temp.EndsWith(".js") && !temp.EndsWith("#") && !(temp.IndexOf("+") > 0) && !temp.StartsWith("javascript") && !temp.StartsWith("mailto"))
  {
  if (!temp.StartsWith("http:"))
  {
  if (temp.StartsWith("../"))
  {
  temp = @"http://henu.2008.163.com/" + temp.Substring(3);
  }
  else
  {
  temp = header + temp;
  }
  }
  if (!siteList.Contains(temp))
  { siteList.Add(temp); }
  //listBox1.Items.Add(temp);
  }
  match = match.NextMatch();
  }

上不了岸的鱼 | 园豆:4613 (老鸟四级) | 2008-12-11 15:45
0

http://119.147.41.16/down?cid=9C8C7592DC5502F64D026FFE5DADD06EBF6E5A4C&t=4&fmt=flv

 

这一部分应该还是比较容易的,

 

还有[ <strong>情 </strong> <strong>归 </strong> <strong>巴黎 </strong>].Sabrina.(1995).CD1

这个没有看明白?

孤剑 | 园豆:328 (菜鸟二级) | 2008-12-11 23:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册