We’re improving Formula Genius. We’re redesigning the app and fixing issues along the way. Sorry for any disruption, and thank you for your patience.
Regex beginner

Regex to Extract Numbers From Any Text

Pull numbers out of messy text data — prices, measurements, IDs, or any numeric value embedded in strings.

Formula Genius can generate a draft from a plain-English prompt. Supported formulas can be checked with sample cases; review the coverage on the result.

The formula

Prompt

"Extract all numbers (including decimals) from a text string"

Regex
-?\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

  1. -? — optional negative sign
  2. \\d+ — one or more digits (the integer part)
  3. \\.? — optional decimal point
  4. \\d* — zero or more decimal digits
  5. 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

Prompt

""The price is $42.99 for 3 items""

Regex
42.99, 3
Prompt

""Temperature: -15.5 degrees""

Regex
-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 a formula in plain English. Formula Genius drafts and explains it, and can check supported formulas on sample cases.