REGEXEXTRACT Returns #N/A in Google Sheets

REGEXEXTRACT returns #N/A when a valid pattern finds no match, and #REF! when the pattern is invalid. Read the message, then use IFNA or fix the regex.

本文目錄

Google Sheets REGEXEXTRACT returns #N/A when a valid regular expression finds no match in the referenced cell. A different failure occurs when the regular expression itself is invalid: the cell shows #REF!, and the message says parameter 2 is not a valid regular expression.

These errors need different fixes. A missing match might deserve a blank or a short fallback. An invalid pattern has to be rewritten before you hide anything.

Consider this building-maintenance ticket log in A1:C10:

TicketFloorNotes
T-1013East stair leak assigned WO-1842
T-1025Buzzing ballast reported
T-103LobbyBadge reader stuck; WO-2075 opened
T-1042Inspect ceiling stain
T-1054WO-3196 awaiting replacement part
T-1061Door closer needs adjustment
T-1076Filter replacement under WO-4281
T-108LobbyReception light flickering
T-1093Follow up on WO-5630 tomorrow

To extract the work-order code from C2, enter this formula in D2:

=REGEXEXTRACT(C2,"WO-[0-9]{4}")

It returns WO-1842. The pattern looks for the literal WO- followed by exactly four digits. That same formula will not produce a code for every row, because some notes contain no work-order reference.

A valid pattern returns #N/A when the cell has no match

The note in C3 is Buzzing ballast reported. It contains no work-order code.

=REGEXEXTRACT(C3,"WO-[0-9]{4}")

The result is #N/A. The message is: Function REGEXEXTRACT parameter 2 value "WO-[0-9]{4}" does not match text of Function REGEXEXTRACT parameter 1 value "Buzzing ballast reported".

Google Sheets with D3 selected, showing =REGEXEXTRACT(C3,"WO-[0-9]{4}") in the formula bar and #N/A for the note Buzzing ballast reported. Rows whose notes contain a work-order code return WO-1842, WO-2075, WO-3196, WO-4281 and WO-5630.
Screenshot: Google Sheets, Nov 2026

The formula is not necessarily broken, and the note is not necessarily incorrect. The cell simply does not contain the token you’re asking REGEXEXTRACT to find.

Compare it with C4, which contains Badge reader stuck; WO-2075 opened. The same expression:

=REGEXEXTRACT(C4,"WO-[0-9]{4}")

returns WO-2075. The formula evaluates the same pattern on both cells. Only one cell supplies a match.

Use IFNA when a missing code is acceptable

If the ticket log allows notes without work-order codes, a column of #N/A values is harder to read. Wrap REGEXEXTRACT with IFNA:

=IFNA(REGEXEXTRACT(C3,"WO-[0-9]{4}"),"No work order")

For C3, this returns No work order. For C4, the equivalent formula returns WO-2075.

If you prefer an empty-looking result, use an empty string as the fallback:

=IFNA(REGEXEXTRACT(C3,"WO-[0-9]{4}"),"")

The cell looks blank. It is not a genuinely empty cell: ISBLANK on that result is FALSE, LEN is 0, and COUNTA still counts it as 1. That difference matters if another formula later counts the column.

I would use IFNA here rather than IFERROR. IFNA handles the expected no-match #N/A without automatically suppressing a different error. The distinction is covered in IFERROR vs IFNA.

Don’t add the wrapper until you’ve checked that the pattern works on a note containing a known code.

An invalid regular expression returns #REF!

A different problem occurs when REGEXEXTRACT cannot interpret the pattern itself. Suppose you copy a regular expression that contains a positive lookahead:

=REGEXEXTRACT(C2,"WO-[0-9]{4}(?= )")

The (?= ) portion is a positive lookahead. Google Sheets uses the RE2 regular-expression engine, which does not support lookahead assertions. C2 definitely contains WO-1842, so the problem is not missing data.

The cell shows #REF!, and the message is: Function REGEXEXTRACT parameter 2 value "WO-[0-9]{4}(?= )" is not a valid regular expression.

REGEXEXTRACT rejects the expression before it can extract the code.

Rewrite the pattern instead of hiding the error

For this ticket log, the lookahead is unnecessary. The work-order code already has a recognizable structure:

=REGEXEXTRACT(C2,"WO-[0-9]{4}")

The corrected formula returns WO-1842.

If you need to make sure the four digits are not part of a longer number, use a supported word boundary rather than a lookahead:

=REGEXEXTRACT(C2,"WO-[0-9]{4}\b")

This also extracts WO-1842 from C2. A word boundary is not identical to a lookahead for a space. It checks the transition between word and non-word characters, so use it only when that matches your data.

The important point is that an invalid parameter 2 requires a pattern change. Wrapping the lookahead formula with IFERROR conceals the problem: =IFERROR(REGEXEXTRACT(C2,"WO-[0-9]{4}(?= )"),"hidden") displayed the fallback text. The same formula wrapped in IFNA still showed #REF! and the invalid-expression message. That is a good reason to prefer IFNA for genuine no-matches: it will not swallow this #REF!.

For more about unsupported lookahead, lookbehind, and backreferences, see Extract Email Addresses with REGEXEXTRACT. That guide covers the relevant RE2 restrictions in more detail.

A pattern anchored to the whole cell misses an embedded code

A regular expression can be valid and still be too tight for the text you’re searching. This formula uses ^ 與 $ to require the entire contents of C2 to be a work-order code:

=REGEXEXTRACT(C2,"^WO-[0-9]{4}$")

C2 contains East stair leak assigned WO-1842, not just WO-1842. The result is #N/A, with the message: Function REGEXEXTRACT parameter 2 value "^WO-[0-9]{4}$" does not match text of Function REGEXEXTRACT parameter 1 value "East stair leak assigned WO-1842".

Remove the anchors:

=REGEXEXTRACT(C2,"WO-[0-9]{4}")

It returns WO-1842. The difference is precise. ^WO-[0-9]{4}$ requires the complete cell value to match the code format. WO-[0-9]{4} searches for that format anywhere inside the text.

Anchors are useful when you are validating a complete value. They are usually the wrong choice when you are extracting a code embedded in a longer maintenance note. For this log, keep the pattern unanchored because the Notes column contains free text.

REGEXMATCH returns FALSE where REGEXEXTRACT returns #N/A

If you’re unsure whether the pattern matches a particular cell, REGEXMATCH is a simple diagnostic. For the note without a work-order code in C3:

=REGEXMATCH(C3,"WO-[0-9]{4}")

The result is FALSE, whereas =REGEXEXTRACT(C3,"WO-[0-9]{4}") returns #N/A. For C2, REGEXMATCH with the same pattern returns TRUE, and REGEXEXTRACT returns WO-1842.

REGEXMATCH answers whether the pattern matches. REGEXEXTRACT returns the matched text. You do not need to replace REGEXEXTRACT with REGEXMATCH in the finished extraction column.

Fill the corrected formula down the ticket log

Once the pattern works on a known matching row and you’ve confirmed how a non-matching row behaves, place this formula in D2 and fill it through D10:

=IFNA(REGEXEXTRACT(C2,"WO-[0-9]{4}"),"No work order")

The resulting output is:

TicketExtracted work order
T-101WO-1842
T-102No work order
T-103WO-2075
T-104No work order
T-105WO-3196
T-106No work order
T-107WO-4281
T-108No work order
T-109WO-5630

This is the version I would keep for the maintenance log. It extracts the token the column needs and gives a readable result when no code is present.

Google Sheets with D2 selected, showing =IFNA(REGEXEXTRACT(C2,"WO-[0-9]{4}"),"No work order") in the formula bar. Filled down D2:D10, it returns each work-order code and No work order for the four notes without one.
Screenshot: Google Sheets, Nov 2026

If your real work-order identifiers have a different format, adjust the expression to match that format rather than adding a broad pattern that captures unrelated numbers. WO-[0-9]{4} deliberately expects four digits. It does not define how to handle five-digit identifiers or codes with different prefixes.

If your task is instead to extract arbitrary numeric values from mixed text, Extract Numbers from Text covers that separate problem.

For a REGEXEXTRACT error, the useful first action remains the same: inspect the error before changing the formula. A valid pattern with no matching code is a data condition you can handle with IFNA. An invalid parameter 2 is a #REF! you need to correct by rewriting the pattern.

Oscar

寫 Excel 與 Google Sheets 的公式和排錯。

Google Sheets, 19 November 2026, new private unshared spreadsheet (locale en_US, 1000-row grid). Formulas were entered as user input through the Sheets API. Error text was read from the Sheets API error message. REGEXEXTRACT(C2,"WO-[0-9]{4}") returned WO-1842. The same pattern on C3 returned #N/A, "Function REGEXEXTRACT parameter 2 value \"WO-[0-9]{4}\" does not match text of Function REGEXEXTRACT parameter 1 value \"Buzzing ballast reported\"." C4 returned WO-2075. IFNA on C3 returned No work order; IFNA on C4 returned WO-2075. IFNA with an empty-string fallback on C3 displayed a blank cell (ISBLANK FALSE, LEN 0, COUNTA 1). REGEXEXTRACT(C2,"WO-[0-9]{4}(?= )") returned #REF!, "Function REGEXEXTRACT parameter 2 value \"WO-[0-9]{4}(?= )\" is not a valid regular expression." The word-boundary pattern WO-[0-9]{4}\\b on C2 returned WO-1842. IFERROR of the lookahead formula displayed the fallback text; IFNA of the same formula left the #REF! and the invalid-expression message visible. The anchored pattern ^WO-[0-9]{4}$ on C2 returned #N/A, "Function REGEXEXTRACT parameter 2 value \"^WO-[0-9]{4}$\" does not match text of Function REGEXEXTRACT parameter 1 value \"East stair leak assigned WO-1842\"." REGEXMATCH on C3 was FALSE; on C2 it was TRUE. Filling IFNA(REGEXEXTRACT(C2,"WO-[0-9]{4}"),"No work order") through D10 returned WO-1842, No work order, WO-2075, No work order, WO-3196, No work order, WO-4281, No work order, WO-5630. Excel was not run.

本主題下一篇:表格錯誤與動態陣列 COUNTIFS Returns #VALUE! in Google Sheets