How to Extract Numbers From Text in Google Sheets
Type =REGEXEXTRACT(A2,"\d+") to pull the first run of digits out of a mixed string like "Order 4521 shipped".
=REGEXEXTRACT(A2,"\d+")
\d+ matches one or more digits and returns the first group found. The result is text — wrap in VALUE to get a number.
How it works
REGEXEXTRACT scans a cell for a pattern and returns the first match. \d+ means "one or more digits", so it grabs the first whole number it finds. The output is a text string, so add VALUE if you need to do maths with it. To handle decimals, extend the pattern to \d+\.?\d*. If no number exists, REGEXEXTRACT throws #N/A — wrap it in IFERROR to return a blank instead.
Variations
Return it as a real number
=VALUE(REGEXEXTRACT(A2,"\d+"))
VALUE turns the extracted text into a number.
Extract a decimal number
=REGEXEXTRACT(A2,"\d+\.?\d*")
Matches whole numbers and decimals like 12.5.
Safe version if no number is found
=IFERROR(REGEXEXTRACT(A2,"\d+"),"")
Returns blank instead of #N/A when there are no digits.
Examples
| Scenario | Formula |
|---|---|
| Get the order number from a note | =REGEXEXTRACT(A2,"\d+") |
| Pull a price like 19.99 | =REGEXEXTRACT(A2,"\d+\.\d+") |
FAQ
How do I extract every number, not just the first?
Use REGEXREPLACE to delete non-digits: =REGEXREPLACE(A2,"[^0-9]","") joins all digits into one string.
Why does the extracted number not add up?
REGEXEXTRACT returns text. Wrap it in VALUE: =VALUE(REGEXEXTRACT(A2,"\d+")).
What if some cells have no number?
REGEXEXTRACT returns #N/A. Wrap in IFERROR to fall back to a blank or zero.