REGEXEXTRACT pulls the first piece of text that matches a regular expression out of a string. It is the tool for lifting an order number out of a sentence, a domain out of an email, or digits out of a messy cell, where LEFT, MID and FIND would need long, fragile formulas.
Syntax
=REGEXEXTRACT(text, regular_expression)
text: The text to search.regular_expression: The pattern to look for, as text in quotes. Google Sheets uses the RE2 syntax.
Behavior depends on the pattern:
- No capturing group: returns the entire matched text.
- One capturing group
( ): returns only what is inside the parentheses. - Several capturing groups: returns each group in its own cell, spilling to the right.
- No match:
#N/A.
Basic examples
=REGEXEXTRACT("Order #4521 shipped", "\d+")
Returns 4521: the first run of digits.
=REGEXEXTRACT("ana@example.com", "@(.+)$")
Returns example.com. The parentheses mean only the part after @ is returned.
=REGEXEXTRACT("2026-03-15", "(\d{4})-(\d{2})-(\d{2})")
Returns three cells: 2026, 03, 15.
Regex building blocks
\da digit,\Da non-digit\wa letter, digit or underscore,\Wthe opposite\swhitespace,\Snon-whitespace.any character (except a line break)+one or more,*zero or more,?zero or one{3}exactly 3,{2,4}between 2 and 4[abc]any of a, b, c.[a-z]any lowercase letter.[^0-9]anything but a digit^start of text,$end of text(a|b)a or b(?i)at the start makes the pattern case-insensitive
Matching is case-sensitive by default.
In a normal Sheets formula, type backslashes as written: "\d+". You do not need to double them.
Common extractions
First number in a text
=REGEXEXTRACT(A2, "\d+")
For decimals: "\d+\.?\d*".
Email address
=REGEXEXTRACT(A2, "[\w.+-]+@[\w-]+\.[\w.-]+")
Domain from an email or URL
=REGEXEXTRACT(A2, "@([\w.-]+)")
=REGEXEXTRACT(A2, "https?://(?:www\.)?([^/]+)")
The (?:...) group is non-capturing, so only the domain in the second group is returned.
Text between two markers
=REGEXEXTRACT(A2, "\[(.*?)\]")
Returns what is inside the first pair of square brackets. .*? is "as little as possible", so it stops at the first closing bracket.
First and last word
=REGEXEXTRACT(A2, "^\S+")
=REGEXEXTRACT(A2, "\S+$")
Numbers from a currency string
=VALUE(REGEXEXTRACT(A2, "[\d.]+"))
REGEXEXTRACT always returns text, so wrap it in VALUE when you need to calculate with the result.
Extracting from a whole column
REGEXEXTRACT handles one cell. Use ARRAYFORMULA for a column, with IFERROR to hide non-matches:
=ARRAYFORMULA(IFERROR(REGEXEXTRACT(A2:A, "\d+"), ""))
Getting all matches, not just the first
REGEXEXTRACT returns only the first match. To get every number in a text, replace everything that is not a digit with a separator, then split:
=SPLIT(REGEXREPLACE(A2, "\D+", ","), ",")
For "a12b345c6" this returns 12, 345, 6 in separate cells.
Common errors
#N/A: "Did not find match for REGEXEXTRACT". The pattern doesn't match the text. Check case sensitivity (add(?i)), spaces, and escaped characters. Wrap inIFERRORfor rows that may not match.#VALUE!: "Invalid regular expression". A syntax problem: an unclosed bracket or parenthesis, or a feature that RE2 doesn't support, such as lookaheads(?=...)and backreferences in the pattern.- Special characters not escaped. To match a literal
.,?,(,),[,$or+, put a backslash before it. - Number comes back as text. It always does. Use
VALUE. - Only the first group seems to appear. With several groups, the result spills right. Make sure the cells to the right are empty.
REGEXEXTRACT vs. other text functions
- Use
LEFT,RIGHTandMIDwhen the position is fixed. - Use
SPLITwhen a clear delimiter separates the pieces. - Use
REGEXEXTRACTwhen the position varies and the shape of the text is what you know. - Use
REGEXMATCHto test whether a pattern is present, andREGEXREPLACEto change it.
Frequently asked questions
Is REGEXEXTRACT case-sensitive? Yes. Start the pattern with (?i) to ignore case.
What regex flavor does it use? RE2, which supports most common syntax but not lookaheads, lookbehinds or backreferences within the pattern.
Can it return several matches in one call? No. Use the SPLIT(REGEXREPLACE(...)) pattern above.
Does it work on numbers? Yes, the input is converted to text first.
Related Functions
REGEXMATCH: Test whether text matches a pattern.REGEXREPLACE: Replace text that matches a pattern.SPLIT: Split text at a delimiter.SUBSTITUTE: Replace specific text without patterns.ARRAYFORMULA: Apply a formula to a whole range.