Skip to content

Instantly share code, notes, and snippets.

@ovarunendra
Created January 25, 2019 15:24
Show Gist options
  • Save ovarunendra/e1ee4cf451e99267fb4eb7de1ea86e5e to your computer and use it in GitHub Desktop.
Save ovarunendra/e1ee4cf451e99267fb4eb7de1ea86e5e to your computer and use it in GitHub Desktop.
MAC-IP-PORT JS Regex
const MAC_REGEX = '^[a-zA-Z0-9]{12}$';
const IP_REGEX = '(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}';
const PORT_REGEX = '(?::+(\\d{2,4}))?';
const IP_PORT_REGEX = `(${IP_REGEX})${PORT_REGEX}`;
const MAC_IP_PORT_REGEX = `(^${MAC_REGEX}$)|(^${IP_PORT_REGEX}$)`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment