Skip to content

Instantly share code, notes, and snippets.

@daler445
Created February 10, 2021 04:39
Show Gist options
  • Save daler445/fd57fc57a22f1653e7c67e40bbc6a63b to your computer and use it in GitHub Desktop.
Save daler445/fd57fc57a22f1653e7c67e40bbc6a63b to your computer and use it in GitHub Desktop.
Regex to match ipv4 addresses, range and mask
^([01]?\d\d?|2[0-4]\d|25[0-5])(?:\.(?:[01]?\d\d?|2[0-4]\d|25[0-5])){3}(?:\/[0-2]\d|\/3[0-2])?(?:\-([01]?\d\d?|2[0-4]\d|25[0-5]))?$
# true
255.255.255.255/30
255.255.255.0
255.255.255.100-200
# false
255.255.255.255/33
255.255.255.256
255.255.255.200-256
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment