如何获取HTML字符串IMG 标签 的所有属性值遍历

xcfdsarfew 2018-07-22 04:42:10
如:<img src="http://localhost/phpwind6/zx/6.jpg" id="imgs" lang="en-us" alt="测试">
需要遍历出SRC id lang alt的值
...全文
447 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xcfdsarfew 2018-07-22
  • 打赏
  • 举报
回复


引用 1 楼 xuzuning 的回复:
            var s = "<img src=\"http://localhost/phpwind6/zx/6.jpg\" id=\"imgs\" lang=\"en-us\" alt=\"测试\">";
Regex.Matches(s, @"(\w+)\s*=\s*([""']?)(.+?)\2").Cast<Match>().ToList().ForEach(x =>
Console.WriteLine("{0} => {1}", x.Groups[1].Value, x.Groups[3].Value));



var s = "<img src=\"http://localhost/phpwind6/zx/6.jpg\" id=\"imgs\" lang=\"en-us\" alt=\"测试\">";
MatchCollection items = Regex.Matches(s, @"(\w+)\s*=\s*([""']?)(.+?)\2");
foreach(Match item in items) {
Console.WriteLine("{0} => {1}", item.Groups[1].Value, item.Groups[3].Value);
}


我自己改了下,版本太低用不了那个
xuzuning 2018-07-22
  • 打赏
  • 举报
回复
            var s = "<img src=\"http://localhost/phpwind6/zx/6.jpg\" id=\"imgs\" lang=\"en-us\" alt=\"测试\">";
Regex.Matches(s, @"(\w+)\s*=\s*([""']?)(.+?)\2").Cast<Match>().ToList().ForEach(x =>
Console.WriteLine("{0} => {1}", x.Groups[1].Value, x.Groups[3].Value));

110,533

社区成员

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

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

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