Skip to main content
Regexflux

Decimal Number

beginner

Matches decimal numbers with optional sign and fractional part.

numberdecimalfloatparsing

Pattern

/-?\d+\.\d+|-?\d+/g

Try It

0 of 8 strings matched

Explanation

Matches numbers with optional negative sign and optional decimal point with fractional digits.

Test Strings

Matching

  • 3.14
  • -0.5
  • 42
  • 100.00
  • -273.15

Non-matching

  • abc
  • no numbers
  • ---

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /-?\d+\.\d+|-?\d+/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Common Variations

Leading dot

-?(?:\d+\.?\d*|\.\d+)

Also matches .5 (no leading zero)

Related Patterns