Spreadsheet Practice

Why does REGEXMATCH not work on numbers in Google Sheets

Google Sheets formula

=REGEXMATCH(TO_TEXT(A2),"^2026")

REGEXMATCH only accepts text and returns #VALUE! for a number. Convert it first: =REGEXMATCH(TO_TEXT(A2),"^2026").

Result on the example
one result per row in B2, filled down to B7
Excel
See below

See it work

The formula is already in B2, filled down to B7. Change any input and the result updates, or edit the formula to experiment.

How it works

The REGEX functions in Google Sheets work on text only; give them a number and they stop with "Function REGEXMATCH parameter 1 expects text values". TO_TEXT turns 20260412 into the text "20260412", and ^2026 then checks the start of it.

=REGEXMATCH(TO_TEXT(A2),"^2026")

ResultTRUE

  1. A220260412

    The value in A2.

  2. TO_TEXT(A2)"20260412"

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

    • valueA220260412
  3. REGEXMATCH(TO_TEXT(A2),"^2026")TRUE

    REGEXMATCH: TRUE if the text contains a match for the pattern.

    • textTO_TEXT(A2)"20260412"
    • regular_expression"^2026"

In Excel

Excel's text functions accept numbers directly, so no conversion is needed: =LEFT(A2,4)="2026", or =REGEXTEST(A2,"^2026") in Microsoft 365.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=REGEXMATCH(A2&"","^2026")TRUE, FALSE, TRUE…Joining an empty string also turns the number into text.
=LEFT(A2,4)="2026"TRUE, FALSE, TRUE…For a fixed prefix, LEFT is enough and works in Excel too.

Common mistakes

  • TO_TEXT uses the cell's format: a number shown as 20,260,412 becomes "20,260,412". Format ID columns as plain numbers or plain text.
  • Converting can't restore leading zeros that were never stored. Type IDs like 00742 into a column formatted as plain text.

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.

Why does REGEXMATCH not work on numbers

In B2, return TRUE when the order ID in A2 (a number) starts with 2026. Fill down to B7.

Questions

Does REGEXEXTRACT have the same problem?

Yes, all three REGEX functions need text. Use REGEXEXTRACT(TO_TEXT(A2),"\d{4}").

How do I check a whole column of numbers?

Use ARRAYFORMULA: =ARRAYFORMULA(REGEXMATCH(TO_TEXT(A2:A7),"^2026")).

Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine.