
35
HaCK 13:
Want to go beyond basic search and replace? Hack up some
“regex” wizardry.
Google Documents allows you to search and replace text in your document by selecting File→
Find and replace (see Figure 2-9). But this feature permits more than plain replacement of one
snippet with another. You get the full range of so-called regular expressions (select the “Regular
expression” checkbox), a mini programming language that deserves (and has) a book’s worth of
coverage; Jeffrey E. F. Friedl’s Mastering Regular Expressions, Third Edition (O’Reilly) goes into
this topic in great detail. The regular expression (also known as regex) syntax may seem cryptic at
rst, but once you learn it, it offers a quick and powerful way to replace text in your documents.
Here are some regular expression replacement scenarios, along with an explanation of the syntax so
that you can adapt this for your own needs.
You cannot use Undo to roll back changes made with Google’s search-and-replace function. Save your
document before making a change if you’re unsure about the results. Sometimes replacements—especially
using regular expression syntax—may do more than you expected them to do. For instance, unless the “Match
whole word” option is checked, replacing “federation” with “federations” would also change “confederation”
to “confederations”.
Additionally,