IP address

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

IP address

Post by spacebiscuit »

Hi,

I am trying to match the first half of an IP address using:

preg_match_all('![0-9]*.[0-9]*.!',"$ip", $matches);

This however seems to find a match for each level of the address and the period. If I input '255.255.255.0' I want the match to be: '255.255'.

I don't think I am far away, is it possible?

Thanks,
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: IP address

Post by pickle »

/[0-9]{1,3}\.[0-9]{1,3}/
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply