I am going through a large website (1600+ pages) to make it pass Priority 1 W3C WAI. As a result, things like image tags need to have alt attributes.
What would be the
This is perfectly possible with following regEx:
<img([^a]|a[^l]|al[^t]|alt[^=])*?/>
Looking for something that isn't there, is rather tricky, but we can trick them back, by looking for a group that doesn't start with 'a', or an 'a' that doesn't get followed by an 'l' and so on.
Here is what I just tried in my own environment with a massive enterprise code base with some good success (found no false positives but definitely found valid cases):
<img(?![^>]*\balt=)[^>]*?>
What's going on in this search:
So this will match:
<img src="foo.jpg" class="baltic" />
But it won't match either of these:
<img src="foo.jpg" class="baltic" alt="" />
<img src="foo.jpg" alt="I have a value.">