G'day ilcylic,

While it may be possible to use 'grep -P ...', I suspect using 'perl ...' (on the command line) would be a lot simpler.

Regexp::Common provides often-used regexes; Regexp::Common::net has regexes for IP addresses.

Using this module, I'd eliminate lines matching /^$RE{net}{IPv4}/ first; then attempt to match /^\S+\s+.*?$RE{net}{IPv4}/.

For use on the command line:

$ perl -MRegexp::Common=net -wnE '/^$RE{net}{IPv4}/ and next; /^\S+\s+ +.*?$RE{net}{IPv4}/ and say' 127.0.0.1aaa 127.0.0.1 256.0.0.1aaa 127.0.0.1 256.0.0.1aaa 127.0.0.1 aaa 127.0.0.1 aaa 127.0.0.1

Having tested that solution, I noticed your update with examples. For IPv4, all of the octets should be in the range 0-255. I suspect you generated quick-and-dirty examples (by running along the number keys) which has produced invalid IP addresses. Changing 456 to 156 and 654 to 154, the same one-liner matches the way you want:

$ perl -MRegexp::Common=net -wnE '/^$RE{net}{IPv4}/ and next; /^\S+\s+ +.*?$RE{net}{IPv4}/ and say' ADMIN__SANDRO_DESK="123.156.78.90" # ilcylic Desktop # ADMIN__SANDRO_DESK="123.156.78.90" # ilcylic Desktop # ADMIN__SANDRO_DESK="123.156.78.90" # ilcylic Desktop # 06/06/15 SR Chgd SANDRO 121.123.154.99 # 06/06/15 SR Chgd SANDRO 121.123.154.99

— Ken


In reply to Re: Seeker of Regex Wisdom (strings which don't form specific patterns) by kcott
in thread Seeker of Regex Wisdom (strings which don't form specific patterns) by ilcylic

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.