Find all tags with an attribute containing a specific phrase in Eclipse

Posted by Dan on Oct 7, 2008 @ 1:07 PM

If you want to quickly find all tags that have an attribute containing a specific value, you can use the following regular expression:

(?is)<(TAGNAME)\s*[^>]*(ATTRIBUTE)="[^"]*(VALUE)[^"]*"[^>]*>

You can use this from either the Global Search (CTRL+H) or from the Find/Replace (CTRL+F) dialogs (just remember to check the "regular expressions" option.)

You'll need to replace the following tokens in the string with the correct values:

TAGNAME = The name of the tag
ATTRIBUTE = The tag's attribute to search
VALUE = The value to search for in the tag's attribute

This regular expression is designed to find the VALUE anywhere in the attribute's value. If you wanted to find exact values, you can remove the [^"]* around the (VALUE) string to make it find exact values.

For example, to find all anchor tags pointing to the file "hello_world.htm" you could use:

(?is)<(a)\s*[^>]*(href)="[^"]*(hello_world.htm)[^"]*"[^>]*>

Categories: HTML/ColdFusion

Comments for this entry have been disabled.