I have found and fixed a few bugs in the incredibly handy Autolinks plug-in by Chris Lynch but there is one that is still eluding me.
The plugin looks at the links you've defined in the WordPress links manager, looks for strings that match those link names, and converts them into hyperlinks on the fly. The bug that I am trying to fix is that if a link name is already (manually) hyperlinked in the article then Autolink will link it again, giving you a nested anchor which is invalid HTML (even though it works).
Basically, I am trying to come up with a regular expression that is the equivalent to the following human-readable proposition:
- Match all instances of the string "foo"
- But not if they are in between an opening anchor tag and a close anchor tag
For good measure I am also trying to avoid any instance of the string which appear inside the tags themselves (for example, if the word "foo" appears inside the "alt" attribute on an IMG tag).
I've spent about five hours trying different regular expressions with no success. Can anyone help? It's a little bit frustrating that I can express the concept in English in a single sentence, but I can't translate it into a working regexp...