求个正则表达式。高手进!

lang11zi 2007-08-01 07:03:19
<img src="https://ab.cctv.com/img/6eKv0uVZFelwVRyZ39YCdtVBtuM3Y5Fn_wpPCNEStwxIyINeGhYOuOsjJoFFoZyW16JwpyBhyAup.jpg" width="290" height="80" alt="my photo" border="0">

如何把src后的图片地址给匹配了?
...全文
169 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
antoniusguo 2007-08-02
  • 打赏
  • 举报
回复
前面那个 @不应该有的 ,贴了别人的忘记删掉了,哈
antoniusguo 2007-08-02
  • 打赏
  • 举报
回复
@"<img[^>]*(\\s+)src(\\s*)=(\\s*)(?<quo>(\"|')?)([^>/]+/)+(?<img>[^/]+)\\k<quo>[^>]*>",
兔子-顾问 2007-08-02
  • 打赏
  • 举报
回复
@"<img[^>]*src=(['""])?[^'""\s>]*?(?<img>[^'""\s>/]*)\1[^>]*>",
这个地方是不是效率不高啊?
[^>]*
贪婪搜索,先搜索到>表示匹配失败,然后返回来看src...这些,然后选择的让出自己匹配。为什么不用.*?呢
sly520 2007-08-02
  • 打赏
  • 举报
回复
<img[^>]*src\s?=\s?(['""])?[^'""\s>]*?(?<img>[^'""\s>/]*)\1[^>]*>
-过客- 2007-08-01
  • 打赏
  • 举报
回复
try

string yourStr = ....................;
Match m = Regex.Match(yourStr, @"<img[^>]*src=(['""])?[^'""\s>]*?(?<img>[^'""\s>/]*)\1[^>]*>", RegexOptions.IgnoreCase);
if (m.Success)
{
MessageBox.Show(m.Groups["img"].Value);
}
lang11zi 2007-08-01
  • 打赏
  • 举报
回复
6eKv0uVZFelwVRyZ39YCdtVBtuM3Y5Fn_wpPCNEStwxIyINeGhYOuOsjJoFFoZyW16JwpyBhyAup.jpg

我就要这个
lang11zi 2007-08-01
  • 打赏
  • 举报
回复
能解释一下吗
-过客- 2007-08-01
  • 打赏
  • 举报
回复
try

string yourStr = ....................;
Match m = Regex.Match(yourStr, @"<img[^>]*src=(['""])?(?<img>[^'""\s>]*)\1[^>]*>", RegexOptions.IgnoreCase);
if (m.Success)
{
MessageBox.Show(m.Groups["img"].Value);
}

110,534

社区成员

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

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

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