🟩 Sheet Formulas

REGEXEXTRACT in Google Sheets

Use REGEXEXTRACT to pull a piece out of text using a pattern — the first number, a domain from an email, or the text between two markers.

=REGEXEXTRACT(A2, "[0-9]+")

Returns the first run of digits found in A2. "[0-9]+" means one or more digits.

How it works

REGEXEXTRACT takes a text value and a regular expression and returns the first part of the text that matches. Sheets uses RE2 syntax: \d for a digit, \w for a word character, + for one-or-more, .* for anything. Wrap part of the pattern in parentheses to return just that captured group. If nothing matches you get #N/A, so wrap it in IFERROR when a miss is expected.

Variations

Extract a decimal number

=REGEXEXTRACT(A2, "[0-9]+\.?[0-9]*")

Matches an integer or a decimal like 12 or 12.5.

Domain from an email

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

The parentheses capture and return everything after the @.

Text between two markers

=REGEXEXTRACT(A2, "\[(.*?)\]")

Returns what's inside square brackets; .*? matches as little as possible.

Safe extract with a fallback

=IFERROR(REGEXEXTRACT(A2, "[0-9]+"), "")

Returns blank instead of #N/A when the pattern isn't found.

Examples

ScenarioFormula
Pull the order number=REGEXEXTRACT(A2, "[0-9]{4,}")
First word only=REGEXEXTRACT(A2, "^\S+")
Everything before a dash=REGEXEXTRACT(A2, "^(.*?)-")

FAQ

Why does REGEXEXTRACT return #N/A?

The pattern didn't match anywhere in the text. Wrap it in IFERROR to return a blank or default when there's no match.

How do I return just part of the match?

Put parentheses around the part you want to capture; REGEXEXTRACT returns the first captured group.

What regex syntax does Google Sheets use?

It uses Google's RE2 flavor — \d for digits, \w for word characters, + and * for repetition, and .*? for a lazy match.

Related formulas