dans.blog


The miscellaneous ramblings and thoughts of Dan G. Switzer, II

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

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)[^"]*"[^>]*>


Finding all matching open/close tags in Eclipse

If you want to quickly find all matching open and close tags, you can use the following regular expression:

(?is)<(TAGNAME)\b[^>]*>(.*?)</\1>

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.)

The "(?is)" makes the regular expression ignore case and search over multiple lines. Just replace the string "TAGNAME" with the tag you want to search. For example, to find all <cfloop> tags, just do:

(?is)<(cfloop)\b[^>]*>(.*?)</\1>