in reply to Regular expression range question (was: Clueless newbie - help!)
You might notice the pattern in the regexp that looks like \d{1,3}\. which means "match any number at least one time, and no more than three times and then a dot". This is a very general IP pattern. The above code also matches the last set (via the parenthases), and then compares it in the other half of the if statement.my $txt = "169.254.0.210"; if($txt =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.(\d{1,3})/ and ($1 < 250 && $1 > 220)) { print "VALID ADDRESS!\n"; }
If you are SURE of the first three octects of your IP address, this will work just fine for you. Hope this helps.if($ip =~ /123\.45\.678\.(\d{1,3})/ and ($1 < 1 and $1 > 126)) #code here
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Clueless newbie - help!
by dsb (Chaplain) on May 08, 2002 at 21:25 UTC |