To be honest, I don't have the patience to do this manually, right now. A much more interesting problem would be writing a somewhat generic algorithm to create such regexes. I posted a regex generator for a closely related problem to the fun-with-perl list a while ago. Since adapting it to your question would take more fiddling than I currently have the stamina for, I'll simply outline the structure of the resulting regex (written in /x syntax for the purposes of this post):

0* (?: 1\d? | 2 (?: [0-4]\d? | 5[0-5]? ) ) (?: (?: # since we got here, the first 1-3 digits formed a number +< 256 # so allow a dot \. # a near-copy of the surrounding regex goes here to match +next octet ) | # no dot matched: allow digit-only strings forming numbers up +to 2**32-1 # (and remember we might already have matched up to 3 digits!) # this bit needs adjusting to smaller ranges in the nested cop +ies )

You can see that it's highly formulaic.

It might make an interesting project to generalize a few numeral-matching pattern builders sufficiently to make them into a module (if such a thing doesn't already exist). I've built such regexen by hand often enough that I've gotten thoroughly sick of doing it; it's a nearly trivial but mind numbingly tedious task.

Makeshifts last the longest.


In reply to Re: (Golf) Expression for matching numeric IP addresses by Aristotle
in thread (Golf) Expression for matching numeric IP addresses by trantor

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.