dotted-quad RE

Joshua Goodall joshua at roughtrade.net
Thu Jul 11 08:06:42 CDT 2002


On Thu, Jul 11, 2002 at 10:51:30PM +1000, Paul Fenwick wrote:
> G'day Joshua,
> 
> On Thu, Jul 11, 2002 at 05:09:59PM +1000, Joshua Goodall wrote:
> > I'm using the following (independently contrived) RE to pick out dotted-quad
> > IPv4 addresses (like 192.168.0.1):
> > 
> > $dqa = qr/1?\d{1,2}|2[0-4]\d|25[0-5]/;
> > $dq  = qr/(?:$dqa\.){3}$dqa/;
> > 
> > print "matched" if $input =~ /^$dq$/;
> 
> Yup, I've got a very simple way:
> 
> 	use Regexp::Common;
> 
> 	print "matched\n" if $input =~ /^$RE{net}{IPv4}$/;

That's very elegant (as is the rest of Regexp::Common)!  CPAN
supplies it, of course, although my particular usage must live
without.

Looking inside, seems Dr Conway used almost the same form as I did,
which is reassuring ... I think he made better use of nongreedy
forms, though.

J



More information about the Melbourne-pm mailing list