DevKits

Numbers

Match an integer

Match positive or negative integers.

Pattern

Regular expression

-?\d+

How it works

Optional minus sign, then one or more digits. Anchor with `^` and `$` if the entire string must be an integer.

Matches

  • 0
  • 42
  • -1
  • 1000000

Non-matches

  • 3.14
  • abc
  • 1e5

Language snippets

JavaScript

const re = /-?\d+/g;

Python

re.findall(r"-?\d+", text)

Go

re := regexp.MustCompile(`-?\d+`)

Java

Pattern.compile("-?\\d+")

Related patterns

Try any pattern live in the Regex Tester