Skip to content

Instantly share code, notes, and snippets.

@ctorgalson
Created October 15, 2012 22:37
Show Gist options
  • Save ctorgalson/3896112 to your computer and use it in GitHub Desktop.
Save ctorgalson/3896112 to your computer and use it in GitHub Desktop.
Private IPv4 Addresses
// This pattern matches IPv4 private IP ranges, plus loopback address.
//
// Pattern 1 matches the beginning of the IP address only, so it cannot be used
// in situations where the entire matched IP address is required.
//
// Pattern 2 returns the entire matched IP address.
//
// @see https://en.wikipedia.org/wiki/IP_address#IPv4_private_addresses
var pattern1 = /^(127\.0\.0\.1)|(10\.)|(192\.168)|(172\.(1[6-9]|2[0-9]|3[0-1])\.)/g,
pattern2 = /^(127\.0\.0\.1)|(10\.\d+\.\d+\.\d+)|(192\.168\.\d+\.\d+)|(172\.(1[6-9]|2[0-9]|3[0-1])\.\d+\.\d+)/g;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment