Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.