REGEXEXTRACT "is not a valid regular expression" and #N/A in Sheets
REGEXEXTRACT shows #REF! with "is not a valid regular expression", or #N/A when nothing matches. The patterns RE2 rejects and each fix.
On this page
=ARRAYFORMULA(REGEXEXTRACT(B2:B7, "(?<=#)\d+"))Before Broken tab
| A | C | D | E | |
|---|---|---|---|---|
| 1 | Customer | Order # | Mentions order | |
| 2 | Emily | #REF! | emily.carter@example.com | FALSE |
| 3 | Jacob | jacob.reed@example.com | TRUE | |
| 4 | Olivia | #N/A | FALSE | |
| 5 | Michael | michael.b@example.com | FALSE | |
| 6 | Sarah | sarah.kim@example.com | TRUE | |
| 7 | Ryan | ryan.ortiz@example.com | FALSE |
What changed
C2pattern#(\d+)C2andD2wrapped in IFNAE2pattern starts with(?i)
After Fixed tab
| A | C | D | E | |
|---|---|---|---|---|
| 1 | Customer | Order # | Mentions order | |
| 2 | Emily | 48213 | emily.carter@example.com | TRUE |
| 3 | Jacob | 50177 | jacob.reed@example.com | TRUE |
| 4 | Olivia | FALSE | ||
| 5 | Michael | 49920 | michael.b@example.com | TRUE |
| 6 | Sarah | 51034 | sarah.kim@example.com | TRUE |
| 7 | Ryan | 50402 | ryan.ortiz@example.com | TRUE |
In Sheets, REGEXEXTRACT gives you "is not a valid regular expression" when the pattern itself is bad, and #N/A when a perfectly fine pattern finds nothing, and this customer-notes sheet manages both. Column C was supposed to pull the order number out of each note in column B with =ARRAYFORMULA(REGEXEXTRACT(B2:B7, "(?<=#)\d+")) in C2, and Sheets put #REF! there with a red box beside it: Function REGEXEXTRACT parameter 2 value "(?<=#)\d+" is not a valid regular expression. Everything under C2 stayed blank too, even the five notes that clearly have an order number in them. The cause is the engine. Sheets reads patterns with RE2, RE2 has no lookbehind, so (?<=#) is a non-starter. A capture group gets the same digits, and "#(\d+)" returned 48213, 50177, 49920, 51034 and 50402 on the Fixed tab.
#REF! on its own tells you almost nothing. Read the box instead. It names parameter 2, the pattern, and quotes it back at you, so Sheets turned the pattern down before it looked at a single note.
There's more wrong in the same sheet, it's quieter about it. The email column shows #N/A for one customer, and the "Mentions order" column says FALSE for three notes that obviously mention an order. The copy you can take home keeps all three broken on the Broken tab.
Why does REGEXEXTRACT reject (?<=#)\d+ in C2?
The (?<=#) at the front is a lookbehind, and the regex engine in Sheets doesn't do those. Google's REGEXEXTRACT help page says Sheets supports RE2 except Unicode character class matching, which reads like near-full support until you open the RE2 syntax reference and find (?<=re), "after text matching re", marked NOT SUPPORTED. The lookahead form (?=re) has the same label. I'd half expected lookahead to make it. Nope. The logic of the pattern is fine, Sheets won't take it as written and that's that.
Lookbehind was only there to keep the # out of the result, and RE2 has another way to do that: parentheses around the part you want. When the pattern has a capture group, REGEXEXTRACT returns what the group matched instead of the whole match. Well, the help page says it from the other side (no capture groups, you get the whole match), but it comes to the same thing. On the Fixed tab, C2 holds:
=ARRAYFORMULA(IFNA(REGEXEXTRACT(B2:B7, "#(\d+)"), ""))
Sheets still matches the #, but only the digits inside the parentheses come back. Emily's row returns 48213 and Ryan's returns 50402, even with ORDER #50402 in capitals in his note, because the pattern never mentions the word at all. Olivia's note has no # anywhere. Without IFNA her row would show #N/A, and that's the same thing going on in the email column.

Why is D4 #N/A when the email pattern works on the other rows?
Olivia's note has no email address in it either, so the pattern finds nothing and REGEXEXTRACT returns #N/A for her row only. Column D uses =ARRAYFORMULA(REGEXEXTRACT(B2:B7, "[\w.]+@[\w.]+")) and the other five rows come back with an address. Click D4 and the box spells out the mismatch, quoting the pattern and the full text it searched:
Function REGEXEXTRACT parameter 2 value "[\w.]+@[\w.]+" doesn't match text of Function REGEXEXTRACT parameter 1 value "Called about shipping times, no order yet".
The pattern is fine here, and the damage looks nothing like C2. A bad pattern breaks the whole ARRAYFORMULA and leaves C3:C7 empty, while a note with no match only costs its own row. One broken pattern, whole column gone. One note with nothing to find, one cell. Jacob, Michael, Sarah and Ryan still got their addresses in D3 and D5:D7.
If you'd rather see an empty cell for those rows, wrap the REGEXEXTRACT in IFNA, like D2 on the Fixed tab:
=ARRAYFORMULA(IFNA(REGEXEXTRACT(B2:B7, "[\w.]+@[\w.]+"), ""))
Clicking D4 also tells you where to edit. The formula bar shows #N/A, not a formula, since D4 is part of the result spilling down from D2. Go up to D2, the top cell, to change it.
![Broken tab with D4 selected. The formula bar shows #N/A, D4 shows #N/A, and the Error box reads: Function REGEXEXTRACT parameter 2 value "[\w.]+@[\w.]+" does not match text of Function REGEXEXTRACT parameter 1 value "Called about shipping times, no order yet".](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-k2AiDrzmUIHTh6-Ozzu9pVeLpFs5Q7hImjhNDBaCdMqpMmpA_uEMITQMcG04Dr5g9q82irppsLkGHaZgre7TMYN1HSXcS0OsGx0nrg7c8geWCGisXOupcVbJMyK8FdkIsXMr8CobaMpVnFMXtqw7rL7muyQg3NWGQSKvQgmhKbm4KPAJquMBZSZamDhp/s1600/broken-d4.png)
Why does REGEXMATCH return FALSE for "Order #48213" and "ORDER #50402"?
The match is case sensitive, and the pattern spells order in lower case. REGEXMATCH doesn't give #N/A for a miss. It gives FALSE, and a column of TRUE and FALSE doesn't exactly look broken.
Column E on the Broken tab checks each note with =ARRAYFORMULA(REGEXMATCH(B2:B7, "order #\d+")). It returned TRUE for Jacob and Sarah, whose notes say "order" in lower case, and FALSE for Emily, Michael and Ryan, whose notes start with Order or ORDER.
The RE2 reference lists the flag i, case-insensitive, as "default false". Turning it on is four characters at the start of the pattern:
=ARRAYFORMULA(REGEXMATCH(B2:B7, "(?i)order #\d+"))
With (?i) in front, E2:E7 on the Fixed tab came back TRUE for every row except Olivia's, and hers has no order number anyway. The REGEXMATCH help page names RE2 as the syntax too, and the other flags sit in the RE2 reference under (?flags).
Four more patterns that make REGEXEXTRACT and REGEXMATCH return #REF!
Same error, different reasons. On the More causes tab an unclosed parenthesis, a plus sign with nothing in front of it, a backreference and a lookahead all returned #REF!. Figure 4 is the Error box for B3.
| Cell | Pattern | Problem | Sheets showed | Working pattern | Result |
|---|---|---|---|---|---|
| B2 | #(\d+ | The group is never closed | #REF! | #(\d+) | 48213 |
| B3 | +1 [\d ]+ | A bare + has nothing to repeat | #REF! | \+1 [\d ]+ | +1 555 0142 |
| B4 | #(\d+).*#\1 | Backreference | #REF! | two REGEXEXTRACT calls compared with = | TRUE |
| B6 | \w+(?=@) | Lookahead | #REF! | ([\w.]+)@ | jacob.reed |
Two of those are plain typos. In #(\d+ the parenthesis that opens the group never closes. In +1 [\d ]+ the + at the start means "one or more of the thing before", and there's nothing before it. Stick a backslash in front, \+, and it matches a literal plus sign instead. When I tried the working version it returned +1 555 0142 from the phone note.
Rows 4 and 6 are a different story, because RE2 leaves both features out. The syntax reference marks \1, a backreference, as NOT SUPPORTED, so a pattern that asks "is the same order number repeated?" has to turn into two extractions. D4 compares the first number after # with the last one, =REGEXEXTRACT(A4, "#(\d+)")=REGEXEXTRACT(A4, "#\d+.*#(\d+)"), and returned TRUE. The lookahead in B6 went the same way as the lookbehind on the Broken tab, and a capture group that ends at the @ does the job and returned jacob.reed.
![More causes tab with B3 selected. The formula bar shows =REGEXEXTRACT(A3, "+1 [\d ]+"), B3 shows #REF!, and the Error box reads: Function REGEXEXTRACT parameter 2 value "+1 [\d ]+" is not a valid regular expression.](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjvApEKrJl5jwU8JDIfAnLczKEo4cGuDfppdNADLQ77Us-Xd0yw6ec_Cohq-BC5qFYTvtzbecJw0rP635nghoHsEJ4KrQSEOEmuiKV08Yum19uHt83ozzZmOgDELSGb1GJgxdu5fxSTlCD6KfwkiIb6nlPvSjGTaskp_d_M1e6oQuyQW0_TC7Mj4AQJk3bZ/s1600/more-b3.png)
What does "parameter 1 expects text values" mean for 48213 in A5?
This one means the cell REGEXEXTRACT is reading holds a number, and the function only takes text. On the More causes tab, A5 has 48213 typed as a number, right-aligned like any number, and =REGEXEXTRACT(A5, "^\d{2}") in B5 shows #VALUE! with this box:
Function REGEXEXTRACT parameter 1 expects text values. But '48213' is a number and can't be coerced to a text.
Both help pages say these functions only work with text as input and suggest converting numbers with TEXT. =REGEXEXTRACT(TEXT(A5, "0"), "^\d{2}") in D5 returned 48. A column of bare order numbers, typed with no # in front, will hit this on every single row.
It goes the other way too, which surprised me more than it should have. Whatever REGEXEXTRACT hands back is text, and that's why the order numbers on the Fixed tab sit left-aligned in column C. =ISTEXT(Fixed!C2) in B7 of More causes returned TRUE. If you need to compare them, sort them as numbers or look them up against a numeric column, wrap them in VALUE. =ISNUMBER(VALUE(Fixed!C2)) in D7 returned TRUE.

Order numbers in Fixed!C2:C7
| Input | Customer notes in B2:B7, with no order number in B4 |
|---|---|
| Formula | =ARRAYFORMULA(IFNA(REGEXEXTRACT(B2:B7, "#(\d+)"), "")) |
| Expected | 48213, 50177, 49920, 51034, 50402 |
| Sheets returned | 48213, 50177, 49920, 51034, 50402 Matches expected |
| Checked | 2026-11-11, free personal account |
The Try it yourself tab is a copy of the Broken tab. Select C2, hit Delete and type =ARRAYFORMULA(IFNA(REGEXEXTRACT(B2:B7, "#(\d+)"), "")), then do the same in D2 with =ARRAYFORMULA(IFNA(REGEXEXTRACT(B2:B7, "[\w.]+@[\w.]+"), "")) and in E2 with =ARRAYFORMULA(REGEXMATCH(B2:B7, "(?i)order #\d+")). Columns C to E should then match the Fixed tab row for row, with C4 and D4 blank and E4 FALSE.

Test a pattern in one cell before putting it inside ARRAYFORMULA. On the Broken tab, one rejected pattern in C2 left C3:C7 empty, while D2, which had a valid pattern, failed only on the row with no match.
Take-home copy. Four tabs: Broken, Fixed, Try it yourself, More causes. It opens as a copy in your own Drive.