Searching for stuff in the DOM

McBachmann and me just discussed regular expression literals in JavaScript and came up with a nice little tip:

If you want to search a web page even if it’s DOM has already been changed via JavaScript routines, you can use the ability of modern (as in Firefox/Opera or Webkit based) browsers to execute custom Javascript on any web page to match any DOM elements HTML representation against a regular expression for example. Firefox can do this via the Firebug extension. Safari, Chrome and Opera are already equipped with a JavaScript console.

An example? Here you go:

alert(
    /\b\w*\b/.exec(
        document.getElementsByTagName('body')[0].innerHTML)
    )
);

This will output the first occurrence of a string matching the given regular expression.

You won’t need this every day, but it may come in handy.