Complete Regex Guide for Advanced Search and Replace in Google Docs™

Google Docs (and Advanced Search and Replace) uses the powerful RE2 regex engine. Just tick “Use regex” in the sidebar and you’re ready to go!

Pattern Meaning Example / Common Use
. Any character except newline a.c → abc, a2c, a c
\d Digit 0–9 \d{4} → 2025
\w Letter, digit or underscore \w+ → word123
\s Whitespace (space, tab, newline) \s{2,} → multiple spaces
^ Start of paragraph/line ^Hello → only at beginning
$ End of paragraph/line end$ → only at end
\b Word boundary \bcat\b → cat but not catch
| OR cat|dog
* 0 or more a* → aaaa or nothing
+ 1 or more \d+ → 1, 12, 12345
? 0 or 1 (also makes previous lazy) colou?r → color & colour
{3} Exactly 3 \d{3} → 123
{3,} 3 or more \s{3,} → 3+ spaces
{2,5} Between 2 and 5 \w{2,5} → 2–5 letter words
(abc) Capturing group – remember matched text Use $1, $2 in Replace
$1, $2, … Insert captured group in replacement Find (\w+) (\w+) → Replace $2 $1 (swap names)
[abc] Any one of a, b, or c [aeiou] → any vowel
[^abc] Anything EXCEPT a, b, c [^0-9] → non-digits
[a-z] Any lowercase letter
[0-9] Any digit (same as \d)
\n Paragraph break / newline Remove extra lines: \n{3,}
\t Tab
\f Page break / form feed Remove all page breaks: leave Replace empty
\., \*, \?, etc. Literal dot, asterisk, question mark…

Most Useful Ready-to-Use Patterns

Goal Find (Regex) Replace With
Reduce multiple spaces to one \s{2,} (single space)
Remove triple+ blank lines \n{3,} \n\n
Find all email addresses [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,} $0 (or link them with format-based replace)
Find URLs (http/https) https?://[^\s]+ $0
Standardize US phone numbers \b(\d{3})[.\- ]?(\d{3})[.\- ]?(\d{4})\b ($1) $2-$3
Swap first and last name (\w+) (\w+) $2 $1
Remove all page breaks \f (leave empty)
Find words longer than 15 letters \b\w{16,}\b (highlight or correct)