Decimal Number
beginnerMatches decimal numbers with optional sign and fractional part.
numberdecimalfloatparsing
Pattern
/-?\d+\.\d+|-?\d+/gTry 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
| Language | Support |
|---|---|
| JS | Full support |
| PYTHON | Full support |
| JAVA | Full support |
| PHP | Full support |
| GO | Full 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)