๐ŸŸฉ Sheet Formulas

Google Sheets Regex Tester (REGEXEXTRACT / REGEXMATCH / REGEXREPLACE)

Quick answer: Google Sheets uses the RE2 regex engine. Test a pattern live above, then paste the generated formula: =REGEXEXTRACT(A1, "pattern") pulls out the first match (or its first capture group), =REGEXMATCH(A1, "pattern") returns TRUE/FALSE, and =REGEXREPLACE(A1, "pattern", "replacement") swaps every match.

Paste your text and a pattern to see every match highlighted as you type, check which capture group REGEXEXTRACT will return, then copy the exact REGEXEXTRACT, REGEXMATCH or REGEXREPLACE formula for your sheet.

=REGEXEXTRACT(A1, "[\w.]+@([\w.]+)")

How this regex tester works

Google Sheets runs the RE2 regular-expression engine, not PCRE, so a few habits from other tools don't apply: there are no lookaheads/lookbehinds ((?=...), (?<=...)) and no backreferences inside the pattern. Everything else you'll reach for โ€” character classes [A-Za-z], shorthands \d \w \s, quantifiers * + ? {2,4}, anchors ^ $, alternation a|b and capture groups (...) โ€” works exactly as the tester above shows.

REGEXEXTRACT returns text: if your pattern has a capture group (...), it returns the first group; with no group it returns the whole match. That's the single most common gotcha โ€” wrap the part you actually want in parentheses. REGEXMATCH returns TRUE or FALSE and is perfect inside FILTER, IF or conditional formatting. REGEXREPLACE swaps every match and lets you reference capture groups in the replacement with $1, $2, etc.

Because the pattern is a text argument, every backslash and quote lives inside quotes in the formula โ€” the builder above handles the quoting for you. Tick case-insensitive and it prepends the RE2 flag (?i) to the pattern, which is how you do case-insensitive matching in Sheets.

Common ready-to-paste examples

Pull the domain out of an email address:

=REGEXEXTRACT(A1, "@(.+)$")

Check whether a cell contains any digit:

=REGEXMATCH(A1, "\d")

Extract the first number (including decimals) from text:

=REGEXEXTRACT(A1, "[\d.]+")

Strip everything except digits (clean a phone number):

=REGEXREPLACE(A1, "[^\d]", "")

Case-insensitive test for the word 'paid':

=REGEXMATCH(A1, "(?i)paid")

Swap first and last name separated by a space:

=REGEXREPLACE(A1, "(\w+) (\w+)", "$2 $1")

FAQ

What regex syntax does Google Sheets use?

Google Sheets uses Google's RE2 engine. It supports character classes, shorthands like \d \w \s, quantifiers, anchors, alternation and capture groups, but it does NOT support lookaheads, lookbehinds or backreferences inside the pattern. The tester above matches with RE2-compatible behaviour so your results carry over to your cells.

Why does REGEXEXTRACT return only part of my match?

Because your pattern contains a capture group (...). REGEXEXTRACT returns the first capture group when one exists, and the whole match only when there are no groups. If you want the entire match, remove the parentheses; if you want a specific piece, wrap just that piece in parentheses.

How do I make a regex case-insensitive in Google Sheets?

Prepend the inline flag (?i) to your pattern, for example =REGEXMATCH(A1, "(?i)error"). RE2 has no /i switch, so the flag goes inside the pattern string. Tick the case-insensitive box in the tester and it adds (?i) to the formula for you.

How do I replace text using a pattern?

Use REGEXREPLACE(text, pattern, replacement). It replaces every match, not just the first. You can reuse captured groups in the replacement with $1, $2 and so on โ€” e.g. =REGEXREPLACE(A1, "(\w+) (\w+)", "$2 $1") swaps two words.

Why does my pattern give a formula parse error in Sheets?

Usually an unescaped double quote inside the pattern. Because the pattern is a text argument in quotes, a literal double quote must be doubled (""). The builder above escapes quotes automatically when it writes the formula.