Take the 2-minute tour ×

I am trying to create a proper regular expression to find all anchors in my project with Eclipse File Search.

What I'm looking for:

<a href="some.url" onclick="some onclickHandler">

What I want to accomplish is finding all anchors without an onclick and add it when needed.

Thanks for your help!

share|improve this question
using what language? –  Jeremy Gwa Feb 7 '10 at 3:32
add comment

1 Answer

up vote 3 down vote accepted

You can use the regex <a href="\S+"((?!onclick).)*>. It will find all links without the onclick pattern.

Short explanation for the interesting part ((?!onclick).)*: ?!onclick is a Zero-width negative lookahead. This means the regex engine will match if it does not contain the word onclick. The surrounding ( and .)* tells the regex engine, that the onclick exlusion can be surrounded by any other character.

share|improve this answer
Thanks Steve! That was exactly what I was looking for. –  Robbert van den Bogerd Feb 25 '10 at 12:43
add comment

Your Answer


