Regex To Match Any Numbers But The Last X Digits

Category: Numbers

A regular expression that allows you to match any numbers but the last x digits (last 4 digits in this regex) in a string.

/\d(?=\d{4})/g

Matches:

  • 12345
  • 123456
  • r12345

Non-matches:

  • 1234
  • Regex 134
  • Regex Pattern

See Also:

Rate This Regex
Sending
User Review
0 (0 votes)

Expression Flags

Flags Description
i Ignore case sensitive.
g Allows global search.
m Allows multiline search.