Skip to content

Instantly share code, notes, and snippets.

@JohnPreston
Created February 27, 2020 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnPreston/41e8996bfeea0e3ee973b11fd310b7d2 to your computer and use it in GitHub Desktop.
Save JohnPreston/41e8996bfeea0e3ee973b11fd310b7d2 to your computer and use it in GitHub Desktop.
Regexps for CIDR/IP validation (checks it is within 0-255 range)
ipv4_ip = r'((((((([0-9]{1}\.))|([0-9]{2}\.)|(1[0-9]{2}\.)|(2[0-5]{2}\.)))){3})(((((([0-9]{1}))|([0-9]{2})|(1[0-9]{2})|(2[0-5]{2}))))){1,3})'
ipv4_ip_link = 'https://regex101.com/r/vIL3oX/3'
ipv4_cidr = r'((((((([0-9]{1}\.))|([0-9]{2}\.)|(1[0-9]{2}\.)|(2[0-5]{2}\.)))){3})(((((([0-9]{1}))|([0-9]{2})|(1[0-9]{2})|(2[0-5]{2}))))){1,3})\/(([0-9])|([1-2][0-9])|((3[0-2])))$'
ipv4_cidr_link = 'https://regex101.com/r/vIL3oX/4'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment