查找所有<a> tags in which first attributes isn&#39;t &#39;title&#39;

时间:2016-09-10 15:23:14

标签: c# regex visual-studio-2015

I'm trying to fix my site to meet WCAG 2.0. This means that all links in my site must have a title. To do it right and not miss any <a> tags, I'm ading title to each link as a first attribute :

<a title="..." 

But this site has a lot of links and I'm struggling to find all the links without a title. Can anyone help me with a regular expression that I could use to find all tags that start with <a but the next letter isn't 't'?

If someone has an answer on how to find specific tag without specific attribute it will be even better! I'm working on visual studio 2015

2 个答案:

答案 0 :(得分:2)

通常,在像DOM这样的复杂系统上使用正则表达式并不是一个好主意。但是,在您的(简单)示例中,您可能会相处:

<a(?:(?!\btitle\b)[^>])*>

这会忽略带有title属性的链接,无论它们在哪里。见a demo on regex101.com

<小时/> 请记住它会失败,例如<a href="http://python.org" data="Here comes a title">This one fails</a>不符合您的意图。

答案 1 :(得分:1)

这个怎么样?

(<a )(?!title)

匹配

<a >

但不是:

<a title="..."

试试here