Spreadsheet Practice

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 to B6
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"

  1. A26125550142

    The value in A2.

  2. TO_TEXT(A2)"6125550142"

    TO_TEXT: Converts a number to text, as it is displayed.

    • valueA26125550142
  3. REGEXEXTRACT(TO_TEXT(A2),"^\d{3}")"612"

    REGEXEXTRACT: The first match, or the captured group(s). #N/A when nothing matches.

    • textTO_TEXT(A2)"6125550142"
    • regular_expression"^\d{3}"

In Excel

Excel 365's REGEXEXTRACT converts numbers to text by itself, so =REGEXEXTRACT(A2,"^\d{3}") works as is. =LEFT(A2,3) also works in both apps.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen 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

In 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.