Skip to content

Instantly share code, notes, and snippets.

View ctorgalson's full-sized avatar

Christopher Torgalson ctorgalson

View GitHub Profile
@ctorgalson
ctorgalson / ipv4-private.js
Created October 15, 2012 22:37
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;
@ctorgalson
ctorgalson / na-phone-pattern.js
Last active February 8, 2016 08:24
North American Phone Number Regex
// This pattern matches the phone numbers ONLY (i.e. it does NOT match the
// extension or text) in:
//
// 250-370-8517 or toll free 1-888-370-8517
// 250 370 8517 or toll free 1 888 3708517
// 250 370 8517 or toll free 18883708517
// 604-851-4700 Ext. 646170
// +12503708517
// 1.250.370.8517
// (250) 370-8517