Regex to Extract Numbers From Any Text
Extract Numbers From Text is a Regex pattern that this pattern matches optional negative sign, one or more digits, optional decimal point, and optional decimal digits. Formula Genius generates and validates this formula automatically from a plain-English prompt.
Pull numbers out of messy text data — prices, measurements, IDs, or any numeric value embedded in strings.
The Formula
"Extract all numbers (including decimals) from a text string"
-?\d+\.?\d*
This pattern matches optional negative sign, one or more digits, optional decimal point, and optional decimal digits. Captures integers, decimals, and negative numbers.
Step-by-Step Breakdown
- -? — optional negative sign
- \\d+ — one or more digits (the integer part)
- \\.? — optional decimal point
- \\d* — zero or more decimal digits
- Combined: matches 42, 3.14, -7, 100.00, etc.
Edge Cases & Warnings
- Matches partial numbers in dates: "2026-01-15" extracts 2026, -01, -15
- Phone numbers like 555-1234 may extract as separate numbers
- Currency symbols ($, EUR) are not captured — just the number
- Scientific notation (1e5, 2.5E-3) needs a different pattern
Examples
""The price is $42.99 for 3 items""
42.99, 3
""Temperature: -15.5 degrees""
-15.5
Frequently Asked Questions
How do I extract only integers (no decimals)?
Use \\d+ for integers only. This matches one or more consecutive digits without decimal points.
How do I use this in Google Sheets?
=REGEXEXTRACT(A1, "-?\d+\.?\d*") extracts the first number. For all numbers, use a custom function or REGEXREPLACE to remove non-numeric characters.
Can't find what you need?
Describe any formula in plain English and Formula Genius will generate, explain, and validate it — instantly.