Integer in PY
Matches whole integers, including negative numbers.
Try it in the PY tester →Pattern
regexPY
^-?\d+$Python (re) code
pyPython
import re
pattern = re.compile(r"^-?\d+$")
input_text = "42"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
How the pattern works
`^-?` optionally allows a leading minus sign. `\d+` requires one or more digits. `$` anchors to end.
Examples
Input
42Matches
42
Input
-17Matches
-17
Input
3.14No match
—