How to fix the REGEXEXTRACT "expects text values" error in Google Sheets
Google Sheets formula
=REGEXEXTRACT(TO_TEXT(A2),"^\d{3}")REGEXEXTRACT, REGEXMATCH and REGEXREPLACE only accept text. Convert numbers first: =REGEXEXTRACT(TO_TEXT(A2),"^\d{3}").
- Result on the example
- one result per row in
B2, filled down toB6 - Excel
- See below
See it work
The formula is already in B2, filled down to B6. Change any input and the result updates, or edit the formula to experiment.
How it works
Google Sheets' regex functions refuse numbers: =REGEXEXTRACT(A2,"^\d{3}") on 6125550142 gives "Function REGEXEXTRACT parameter 1 expects text values". TO_TEXT converts the number to the text you see in the cell, and the pattern ^\d{3} then takes the first three digits.
=REGEXEXTRACT(TO_TEXT(A2),"^\d{3}")Result"612"
A26125550142The value in A2.
TO_TEXT(A2)"6125550142"TO_TEXT: Converts a number to text, as it is displayed.- value
A26125550142
- value
REGEXEXTRACT(TO_TEXT(A2),"^\d{3}")"612"REGEXEXTRACT: The first match, or the captured group(s). #N/A when nothing matches.- text
TO_TEXT(A2)"6125550142" - regular_expression
"^\d{3}"
- text
In Excel
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =REGEXEXTRACT(A2&"","^\d{3}") | 612, 651, 763… | Joining an empty text also converts the number. Unlike TO_TEXT, it ignores the cell's number format. |
Common mistakes
- TO_TEXT uses the displayed format: a number shown as 6,125,550,142 becomes text with commas. Use
A2&""when the format gets in the way. - Dates are numbers too. Convert them with
TEXT(A2,"yyyy-mm-dd")to control the result.
Try it yourself
Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.
Fix the REGEXEXTRACT "expects text values" error
B2, extract the first three digits of the phone number, which is stored as a number, and fill down to B6.Questions
Does REGEXMATCH have the same problem?
Yes. Use =REGEXMATCH(TO_TEXT(A2),"^612").
How do I get a number back out?
Wrap the result in VALUE: =VALUE(REGEXEXTRACT(TO_TEXT(A2),"^\d{3}")).
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine.