Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • The prefix length (number after the '/') tells you how many bits make up the network part of the address which is the only part you should be matching. Here you're just matching the first 3 octets which assumes everything is a '/24'. en.wikipedia.org/wiki/CIDR_notation Commented Dec 16, 2010 at 15:58
  • Although I strongly advise using a netmask module that abstracts away the bits, for those bound and determined to use a regex (which just out of sheer cussedness I sometimes myself am :), this seems like a great place to use a “grammatical” regex, with a ((DEFINE)…) block and “regex subroutines”. Commented Dec 16, 2010 at 18:19
  • 1
    This re-invents the wheel - just use Regexp::Common::net. Commented Dec 16, 2010 at 18:39
  • @tchrist: Agree. @Ether: Whoops. I think it's just all my years of CPAN-less Perl environment that makes me code first. Commented Dec 16, 2010 at 19:05