In keeping with TMTOWTDI, the following will correctly match an IPv4 address at the start of a scalar:

/^((\d{1,2}|1\d{2}|2[0-4]\d|25[0-5])\.){3}\2(\s|$) +/

And broken down (to make it look even more complicated):

/ (begin pattern match) ^ (match start of scalar) ( (begin grouping match of '0.' to '255.') ( (begin saving match of '0' to '255', to \2) \d{1,2}| (match '0' to '99' or...) 1\d{2}| (match '100' to '199' or...) 2[0-4]\d| (match '200' to '249' or...) 25[0-5] (match '250' to '255') ) (end saving match of '0' to '255', to \2) \. (match a '.') ) (end grouping match of '0.' to '255.') {3} (match '0.' to '255.' 3 times) \2 (match '0' to '255') (\s|$) (match whitespace or scalar end (when \n absent)) / (end pattern match)

======= BTW, that:

perl -le "s,,reverse killer,e,y,rifle,lycra,,print"

...is pretty /swe{3,}t/. :)

LaurenceHunter => "Life is loud, life is 60p/min."


In reply to Re: Clarify this Regular Expression by Anonymous Monk
in thread Clarify this Regular Expression by dru145

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.