Forum Moderators: coopster

Message Too Old, No Replies

Preg Match All - IP Range

preg match

         

Go3Team

4:20 pm on Nov 12, 2009 (gmt 0)

10+ Year Member



I'm trying to perfrom a preg match all on the results of a whois search. Basically find "123.456.789.0 - 123.546.789.0" in the results.

I've tried a few ways to do it, but keep failing:

preg_match("/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s[-]\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/", $lines[$i], $y)

Can anyone point me in the right direction?

Thanks.

TheMadScientist

5:08 pm on Nov 12, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Something like this is closer:

preg_match("/123\.(4¦5)(4¦5)6\.789\.\d{3}/", $lines[$i], $y);

Depending on the exact range, you might need to adjust the above and will need to replace the broken bar ¦ with a bar... The bar means 'or' so the above matches:

123. followed by 4 or 5 followed by 4 or 5 followed by 6. followed by 789. followed by 'Any Three Numbers'

Go3Team

5:50 pm on Nov 12, 2009 (gmt 0)

10+ Year Member



The IPs are variable, this finally worked for me:

preg_match("/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s-\s\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/", $lines[$i], $y)