Function · Split and regex
Excel REGEXEXTRACT function
The Excel REGEXEXTRACT function returns text that matches a pattern. Capture groups of (512) 555-0148 start with 512.
Syntax =REGEXEXTRACT(text, pattern, [return_mode], [case_sensitivity])
=REGEXEXTRACT(A2,"\([0-9]{3}\) [0-9]{3}-[0-9]{4}")Arguments
| Name | Required | What to pass |
|---|---|---|
| text | Required | The text to search, or a cell that holds it. The result is text, even when the match is digits. A date serial does not contain the characters 03/17/2026. |
| pattern | Required | A regular expression in the PCRE2 flavor, the same flavor REGEXTEST and REGEXREPLACE use. return_mode 0 returns the whole first match. Parentheses mark capture groups for return_mode 2. A backslash escapes a special character, so \( is a literal parenthesis and \$ is a literal dollar sign. An invalid pattern is #VALUE!. |
| return_mode | Optional | 0, the default, is the first match. 1 spills every match across the row. 2 spills the capture groups of the first match across the row. Any other number is #VALUE!. A miss is #N/A. |
| case_sensitivity | Optional | 0, the default, is case-sensitive. 1 ignores case. The result is the text in the cell, so sku against SKU returns SKU. Any other number is #VALUE!. |
Examples
The phone in a Harbor Dental note
=REGEXEXTRACT(A2,"\([0-9]{3}\) [0-9]{3}-[0-9]{4}")Result (512) 555-0148
Area code, exchange, and line
=REGEXEXTRACT(A2,"\(([0-9]{3})\) ([0-9]{3})-([0-9]{4})",2)Result 512, 555, and 0148, spilled across the row
Austin and Boston ZIPs
=REGEXEXTRACT(A2,"[0-9]{5}",1)Result 78701 and 02134, spilled across the row
The amount on invoice 1042
=REGEXEXTRACT(A2,"\$[0-9,]+\.[0-9]{2}")Result $1,250.00
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Phone | Area | Exchange | Line |
| 2 | (512) 555-0148 | 512 | 555 | 0148 |
REGEXEXTRACT returns the text that matches. return_mode 0, the default, is the first match, so (512) 555-0148 comes back whole. return_mode 1 spills every match across the row. return_mode 2 spills the capture groups of that first match, the parts in parentheses, so the same phone spills 512, 555, and 0148. The result is text. VALUE of the extracted $1,250.00 is 1250 in a US workbook. A miss is #N/A, and IFNA can replace it. The pattern language is PCRE2, which is also what REGEXTEST and REGEXREPLACE use. 512-555-0148 does not match a pattern that asks for parentheses and a space. case_sensitivity 0 is case-sensitive. case_sensitivity 1 makes sku match the SKU in Reorder SKU A200, and the result is the letters in the cell.
Excel 2024, Excel 2021, and Excel 2019 return #NAME?. TEXTAFTER of the last space in Austin, TX 78701 is 78701, and that function is in Excel 2024. MID with SEARCH takes the three characters after the parenthesis and returns 512 in older Excel. The format phone LAMBDA, the digits only LAMBDA, the text between LAMBDA, the ZIP shape LAMBDA, the pad ZIP LAMBDA, and the email shape LAMBDA cover those fixed shapes without a regular expression. The Sales Pipeline Tracker formats (512) 555-0148 and checks an email shape. The Wedding Guest List keeps the Boston ZIP 02134 as text. The 1099 Contractor Payment Tracker stores a state, a ZIP, and a phone. The pipeline tracker and the contractor tracker open in Excel 2010.