Regex beginner numbers extract decimal integer

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

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 any formula in plain English and Formula Genius will generate, explain, and validate it — instantly.