Integer
Matches whole integers, including negative numbers.
Try it in RegexPro →Available in
Pattern
^-?\d+$Raw source: ^-?\d+$
How it works
Examples
Input
42Matches
42
Input
-17Matches
-17
Input
3.14No match
—Common use cases
- •Form validation
- •ID parsing
- •Configuration values
Related patterns
Decimal Number
NumbersMatches decimal numbers, including integers and negatives.
Float / Scientific Number
NumbersMatch floating-point and scientific-notation numbers including `1.5`, `.25`, `1e10`, `-3.14E-2`.
Scientific Notation
NumbersMatches numbers in scientific/exponential notation (e.g., 1.5e10).
Binary Number Literal
NumbersMatch binary number literals like `0b1010` or `0B11110000`.
Related concepts
Anchors: ^ and $ Explained
ConceptAnchors match positions, not characters. ^ asserts the start of the string (or line, with the m flag) and $ asserts the end.
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.
Quantifiers: *, +, ?, and {n,m}
ConceptQuantifiers repeat the preceding element. * is 0 or more, + is 1 or more, ? is 0 or 1. {n}, {n,}, and {n,m} give exact counts and ranges.
How to Match Digits in Regex
How-toUse \d for any digit, [0-9] for ASCII digits only, or {n} to match a specific count of digits. Combine with anchors for whole-string validation.