Rob rob at cowsnet.com.au
Thu Jul 11 08:22:06 CDT 2002

```> Yup, I've got a very simple way:
>
> 	use Regexp::Common;
>
> 	print "matched\n" if \$input =~ /^\$RE{net}{IPv4}\$/;

Actually Joshua's regex is very close to the pattern matching in
Regex::Common ...

my %IPunit = (
dec => q{(?k:25[0-5]|2[0-4]\d|[0-1]??\d{1,2})},
oct => q{(?k:[0-3]??[0-7]{1,2})},
hex => q{(?k:[0-9A-F]{1,2})},
bin => q{(?k:[0-1]{1,8})},
);

\$defsep = '[.]';

pattern name   => [qw( net IPv4 )],
create =>
"(?k:\$IPunit{dec}\$defsep\$IPunit{dec}\$defsep\$IPunit{dec}\$defsep\$IPunit{de
c})",
;

Another way would be that from Mastering Regular Expressions ...

^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.
([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])

But I like Paul's approach with Regex::Common, so I would probably use
that myself :-)

Cheers,
Rob

Rob Casey
Cowsnet Internet and Professional Services
http://www.cowsnet.com.au

> -----Original Message-----
> From: owner-melbourne-pm at pm.org
> [mailto:owner-melbourne-pm at pm.org] On Behalf Of Paul Fenwick
> Sent: Thursday, July 11, 2002 10:52 PM
> To: Joshua Goodall
> Cc: Melbourne Perl Mongers