Regex To Match Any Numbers But The Last X Digits

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:

Regex Is Copied!