Extract Numbers From Messy Text
Order references arrive buried in free-typed text — "Order #4521 (rush)", "Invoice INV-0087" — and you need just the number so you can match it against another sheet.
Excel & Google Sheets
How it works
In Google Sheets, REGEXEXTRACT returns the first unbroken run of digits it finds — the pattern [0-9]+ means "one or more digits in a row." What comes back is text, not a number, so multiply by 1 before comparing it to real numbers: =REGEXEXTRACT(A2,"[0-9]+")*1. Classic Excel has no regex functions, so the Excel version tests every character instead: SEQUENCE(LEN(A2)) counts positions 1 through the length of the text, MID grabs the character at each position, and multiplying by 1 keeps digits while turning everything else into an error. IFERROR swaps those errors for empty text, and TEXTJOIN glues the survivors back into one string — leaving only the digits. It looks intimidating, but it is a single copy-paste that handles any text you throw at it.
When to use it
Use it when order numbers, invoice IDs, or quantities are trapped inside notes and subject lines, and you need the bare number to look up against another sheet or add up in a report.
Common mistakes
Did this formula help?
Engine-verified against the sample data aboveLast reviewed 2026-07-08