正则表达式

wangj2001 2004-06-23 08:10:31
<TD class=msc><A class=t
href="http://www.xbom.com/iibs/ZH/buildcoupon.asp?couponchoice=F501154">xxyoup 搜索大全</A></TD>
其中msc,搜索大全是关键字(肯定存在),我想用正则表达式获取一个网页中的url,比如http://www.xbom.com/iibs/ZH/buildcoupon.asp?couponchoice=F501154
...全文
128 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangj2001 2004-06-25
  • 打赏
  • 举报
回复
能写个完整的例子 saucer(思归/MVP)
saucer 2004-06-24
  • 打赏
  • 举报
回复
there is no general way to do that, normally, you would use

(?!.*msc).*

(?!.*搜索大全).*

in your case, it is properly easier to get the TD class and the text in the hyperlink, then check if they contain those words
liduke 2004-06-24
  • 打赏
  • 举报
回复
先将想留的分成组,然后把不等组的替换
wangj2001 2004-06-23
  • 打赏
  • 举报
回复
差一步给分 我怎么才能排除掉clss!=msc 和文字不是“搜索大全”
saucer 2004-06-23
  • 打赏
  • 举报
回复
try


using System.Text.RegularExpressions;


string s= @"<TD class=msc><A class=t href=""http://www.xbom.com/iibs/ZH/buildcoupon.asp?couponchoice=F501154"">xxyoup 搜索大全</A></TD>";

Regex re = new Regex(@"<a[^>]+href=(?:""(?<url>[^""]+)""|'(?<url>[^']+)')", RegexOptions.IgnoreCase);
Match m = re.Match(s);
if (m.Success)
{

Console.WriteLine("{0} is {1}", s, m.Groups["url"].Value);
}

110,557

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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