
38 GOOGLE APPS HACKS
and hyphens without a period (a top-level domain name such as com, edu, or net). So this
regular expression would match www.oreilly.com, using the following steps:
www.
oreilly.
com
As you’ve seen earlier, the $1 refers to the group matched by the rst (in this case, outer) set of
parentheses. The inner set of parentheses could be referred to by $2, but it’s not needed because
it’s a subset of what you’re interested in.
Note that when matching hyphens, the - needs to come at the beginning of the [ ] group or be
escaped with \ because it has special meaning within [ and ], as you saw in “Replacing obfuscated
email addresses with real ones.”
Sometimes you want to replace not just within the visible text, but also within the underlying HTML
source. However when you switch to the HTML mode for a document, the Edit→Find and replace
menu disappears. But you can work around this limitation by using a bookmarklet, a browser
bookmark containing JavaScript. JavaScript also natively supports regular expressions.
First, create a new bookmarklet as described in . The basic JavaScript needed for this is
the following replacement function, where “a” is the (regular expression–based) string to nd, and “b”
the string to replace with:
javascript:(function(){
var ta = document.getElementById("wys_textarea");
ta.value =ta.value.replace("a", "b");
})()
To ex