nanog mailing list archives
Re: Regular Expression for IPv6 addresses
From: Phil Pennock <phil.pennock () spodhuis org>
Date: Sat, 20 Feb 2010 02:08:50 +0100
On 2010-02-04 at 17:50 -0500, Richard E. Brown wrote:
My company, Dartware, have derived a regex for testing whether an IPv6 address is correct. I've posted it in my blog: http://intermapper.ning.com/profiles/blogs/a-regular-expression-for-ipv6 This has links to the regular expression, a (Perl) program that tests various correct and malformed addresses, and a Ruby implementation of the same.
There's a full grammar in RFC 3986 (URI Generic Syntax) already, which can be translated straight. It too handles the embedded IPv4 addresses. While your code is written in a more condensed manner, those who want to be able to cross-check against the RFC might want to take a look at this one, which emits a PCRE regexp: http://people.spodhuis.org/phil.pennock/software/emit_ipv6_regexp-0.304 http://people.spodhuis.org/phil.pennock/software/emit_ipv6_regexp-0.304.asc (Version numbers for repository, not for that one script :) ). FWIW, the ability to grab a shell variable which contains an RE for IPv6 addresses, which can be used in: pcregrep "$ipv6_regex" log_file has proven very useful, especially when debugging newly-added IPv6 support for an app. This is also the most coherent justification I've come up with so far for using a regexp instead of a dedicated parser, other than "because I could". Regards, -Phil
Current thread:
- Re: Regular Expression for IPv6 addresses, (continued)
- Re: Regular Expression for IPv6 addresses Mark Andrews (Feb 04)
- Re: Regular Expression for IPv6 addresses Jeroen Massar (Feb 04)
- Re: Regular Expression for IPv6 addresses Mark Andrews (Feb 04)
- Re: Regular Expression for IPv6 addresses sthaug (Feb 04)
- Re: Regular Expression for IPv6 addresses James Hess (Feb 06)
- Re: Regular Expression for IPv6 addresses Mark Andrews (Feb 06)
- Re: Regular Expression for IPv6 addresses Mark Andrews (Feb 04)
- Re: Regular Expression for IPv6 addresses isabel dias (Feb 05)
- Re: Regular Expression for IPv6 addresses Thomas Habets (Feb 09)
- Re: Regular Expression for IPv6 addresses Mark Andrews (Feb 09)
- Re: Regular Expression for IPv6 addresses Valdis . Kletnieks (Feb 09)