Numbers
Decimal Number
Matches decimal numbers, including integers and negatives.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
^-?\d+(\.\d+)?$Raw source: ^-?\d+(\.\d+)?$
How it works
`^-?\d+` matches optional sign and integer part. `(\.\d+)?` optionally matches a decimal point and fractional digits.
Examples
Input
3.14Matches
3.14
Input
-0.001Matches
-0.001
Input
42Matches
42
Common use cases
- •Price input
- •Scientific data
- •Form validation
Related patterns
Float / Scientific Number
NumbersMatch floating-point and scientific-notation numbers including `1.5`, `.25`, `1e10`, `-3.14E-2`.
Integer
NumbersMatches whole integers, including negative numbers.
Binary Number Literal
NumbersMatch binary number literals like `0b1010` or `0B11110000`.
Hexadecimal Number Literal
NumbersMatch hexadecimal number literals like `0xFF`, `0x1A2B`, or `0XdeadBeef`.
Related concepts
Character Classes: \d, \w, \s and Their Negations
ConceptShorthand character classes match broad categories of characters. \d is a digit, \w is a word character, \s is whitespace. Uppercase negates.
Custom Character Sets: [abc], [a-z], [^abc]
ConceptSquare brackets build a custom character class. [abc] matches any of a, b, or c. [a-z] is a range. A leading ^ negates the set.