Regex to Extract Numbers from a String
Copy the pattern, paste your text below, and see every number it extracts. Below the tester: how it handles decimals, signs, and thousands separators.
What this pattern matches
This extracts every number in the text: whole numbers, decimals, and negative numbers. Use it with a global flag to collect them all.
How it works, part by part
-? — an optional leading minus sign.
\d+ — one or more digits (the integer part).
(?:\.\d+)? — an optional decimal point and fractional digits.
Thousands separators
This treats 1,234 as two numbers (1 and 234). To keep grouped numbers whole, use -?\d{1,3}(?:,\d{3})*(?:\.\d+)? instead.
FAQ
Does it capture decimals?
Yes. 3.50 is matched as one number thanks to the optional decimal group.
Does it handle negative numbers?
Yes. The optional leading - captures -2 as a negative number.
Why does 1,234 split into two?
The base pattern does not know about thousands separators. Use the grouped variant shown above to keep it whole.