Skip to content

Instantly share code, notes, and snippets.

@DamienGarrido
Created October 28, 2015 15:04
Show Gist options
  • Save DamienGarrido/2bde00b54c92d4b8ae1d to your computer and use it in GitHub Desktop.
Save DamienGarrido/2bde00b54c92d4b8ae1d to your computer and use it in GitHub Desktop.
Valid IPv4/v6 regular expression
To get the real regular expression, remove indentation and carriage returns, then replace:
- hexablock with [a-fA-F0-9]{1,4}
- ipv4 with (?:(?:[1-9]?\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:[1-9]?\d|1\d{2}|2[0-4]\d|25[0-5])
(?:
ipv4
|
(?:
(?:hexablock:){7}
(?:
hexablock
|
:
)
|
(?:hexablock:){6}
(?:
:hexablock
|
ipv4
|
:
)
|
(?:hexablock:){5}
(?:
(?::hexablock){1,2}
|
:
ipv4
|
:
)
|
(?:hexablock:){4}
(?:
(?::hexablock){1,3}
|
(?::hexablock)?:
ipv4
|
:
)
|
(?:hexablock:){3}
(?:
(?::hexablock){1,4}
|
(?::hexablock){0,2}:
ipv4
|
:
)
|
(?:hexablock:){2}
(?:
(?::hexablock){1,5}
|
(?::hexablock){0,3}:
ipv4
|
:
)
|
(?:hexablock:){1}
(?:
(?::hexablock){1,6}
|
(?::hexablock){0,4}:
ipv4
|
:
)
|
:
(?:
(?::hexablock){1,7}
|
(?::hexablock){0,5}:
ipv4
|
:
)
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment