Regular expression help

Hi guys, I’m racking my brain out over this one.

I’m trying to create a bit of regular expression which will match an <img> tag which doesn’t have an <a><img></a> around it, so for example, it will match:

<p><img></p>, <span><img></span> and <img>

but not:


This is what I have so far:


But (as i’ve just learned, putting the carrot before the start of the trailing anchor will cause it to not match the image if it has a trailing < rather than a trailing </a>

Any help or advice is appreciated

Is there any reason why you want/need to do with with regex, rather than something probably more appropriate for the task (like DOM)?