in reply to Matching an IP address

well, there's two ways i know of to go about this.

1) The regex from MRE :
^([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])

2) This is a pain in the ass to write out, so if i'm only going to be matching once, i'll sacrifice speed for readability:

sub validip { my ($ip)=@_; my $x; foreach ($ip=~/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/){ $x++ if(($_>=0)&&($_<=255)); } return($x==4); }


BlueLines

Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.