dotted-quad RE

Paul Fenwick pjf at perltraining.com.au
Thu Jul 11 07:51:30 CDT 2002


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}$/;

If you can't or won't have Regexp::Common installed, then consider
making effective use of split.  A fully-correct dotted-quad regexp
isn't understandable by many mortals.

All the best,

	Paul

-- 
Paul Fenwick <pjf at perltraining.com.au> | http://perltraining.com.au/
Director of Training                   | Ph:  +61 3 9354 6001
Perl Training Australia                | Fax: +61 3 9354 2681



More information about the Melbourne-pm mailing list