Regex for integer and decimal number matching in JavaScript

This pattern matches optionally-signed integers and decimals. Anchor it or add thousands separators with the live tester to fit your needs.

Working example
/-?\d+(?:\.\d+)?/g

Try it live

The pattern and sample strings below are pre-loaded. Edit anything, or describe a variation in plain English and generate your own.

Save your patterns across devices.
/-?\d+(?:\.\d+)?/gvalid ✓

One sample per line. Tested live on the JavaScript engine — other flavors are validated and flagged for differences, not executed.

No samples.

Related regex recipes