How to extract a number from text in Google Sheets
Google Sheets formula
=VALUE(REGEXEXTRACT(A2,"-?\d[\d,]*\.?\d*"))Use REGEXEXTRACT with a number pattern and wrap it in VALUE: =VALUE(REGEXEXTRACT(A2,"-?\d[\d,]*\.?\d*")). It keeps decimals, thousands commas and minus signs.
- Result on the example
- one result per row in
B2, filled down toB6 - Excel
- See below
See it work
The formula is already in B2, filled down to B6. Change any input and the result updates, or edit the formula to experiment.
How it works
The pattern reads: an optional minus, a digit, then any digits or commas, an optional decimal point and more digits. REGEXEXTRACT returns the first match as text ("1,250.75") and VALUE turns it into the number 1250.75.
=VALUE(REGEXEXTRACT(A2,"-?\d[\d,]*\.?\d*"))Result12.5
A2"Weight: 12.5 kg"The value in A2.
REGEXEXTRACT(A2,"-?\d[\d,]*\.?\d*")"12.5"REGEXEXTRACT: The first match, or the captured group(s). #N/A when nothing matches.- text
A2"Weight: 12.5 kg" - regular_expression
"-?\d[\d,]*\.?\d*"
- text
VALUE(REGEXEXTRACT(A2,"-?\d[\d,]*\.?\d*"))12.5VALUE: Converts text that looks like a number into a number.- text
REGEXEXTRACT(A2,"-?\d[\d,]*\.?\d*")"12.5"
- text
In Excel
Other ways to do it
Each one was run on the same example sheet.
| Formula | Result | When to use it |
|---|---|---|
| =VALUE(REGEXREPLACE(A2,"[^\d.-]","")) | 12.5, 1250.75, -4… | Deletes everything that isn't a digit, a dot or a minus. Simpler, but only safe when each cell holds one number and no other dots or dashes. |
| =REGEXEXTRACT(A2,"-?\d[\d,]*\.?\d*") | 12.5, 1,250.75, -4…Different result | Without VALUE you get text. Text such as "1,250.75" that won't add up in SUM. |
Common mistakes
- REGEXEXTRACT returns only the first match. "2 boxes of 50" gives 2.
- A cell with no number returns #N/A. Wrap the formula in
IFERROR(…,""). - REGEXEXTRACT needs text. If the cell holds a real number, use
TO_TEXT(A2).
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.
Extract a number from text
B2, extract the number from the note, keeping decimals, commas and a minus sign, and return it as a number. Fill down to B6.Questions
How do I get the second number in the text?
Skip the first one in the pattern: =REGEXEXTRACT(A2,"\d+\D+(\d+)").
How do I keep only the digits?
Delete every non-digit: =REGEXREPLACE(A2,"\D","").
Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine.