【发布时间】:2015-11-04 12:40:00
【问题描述】:
如何使用正则表达式计算img标签中有没有alt标签?
MatchCollection AltTag = Regex.Matches(
strIn,
"<img .*? />",
RegexOptions.IgnoreCase | RegexOptions.Multiline
);
lblImgTags.Text = "We found " + AltTag.Count.ToString() + " images on this website ";
我正在计算 img 这样的标签,但我如何计算没有 alt 标签的 img 标签?
【问题讨论】:
-
Regex 是您最不想为此使用的东西。为什么不使用 jQuery 并将字符串作为 DOM 读取?
-
这可能是相关的:stackoverflow.com/questions/1732348/… regex is not great in parsing html
-
@OliverRadini 我正在寻找但找不到它:D
-
哈哈它看起来很经典
-
你为什么要标记
jquery?您不能在 C# 代码中使用 jQuery,而且您的示例很明显是 C# 代码。为什么要标记javascript?我已经为你删除了不相关的标签。