views:

39

answers:

1

Hi!

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!

+1  A: 

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.

Steve
Thanks Steve! That was exactly what I was looking for.
Robbert van den Bogerd