... a regex for grep -P that would show me lines which had, roughly, ^[one or more non-whitespace chars, which also do not form an IP address][one or more whitespace chars][zero or more chars][an IP address]

My 0.02USD. It's possible to rigorously express all the stated requirements as regexes. It's highly convenient to do so by building upon existing Perl modules such as Regexp::Common.

The requirement
    [one or more non-whitespace chars, which also do not form an IP address]
can be exactly expressed as
    my $S_not_IPv4 = qr{ (?! $RE{net}{IPv4}) \S }xms
for a single such character, and
    $S_not_IPv4+
(within a regex) as "one or more" such characters.

The requirements  [one or more whitespace chars] and  [zero or more chars] are exactly met by  \s+ and  .* respectively.

For
    [an IP address]
it's convenient to use  $RE{net}{IPv4} defined in Regexp::Common::net, but this regex has a subtlety: it intentionally does not include boundary conditions and so may match what might be considered a non-IPv4 string in certain circumstances:

c:\@Work\Perl\monks>perl -wMstrict -le "use Regexp::Common qw(net); ;; print 'match' if '54321.2.3.45678' =~ m{ $RE{net}{IPv4} }xms; " match
The programmer must determine the proper match criteria for each circumstance. I have used a "loose" criterion in the  $S_not_IPv4 definition, and also have a tighter  $ip definition that would exclude the  '54321.2.3.45678' match above.

So finally:

c:\@Work\Perl\monks>perl -wMstrict -le "use Regexp::Common qw(net); ;; my $ip = qr{ (?<! \d) $RE{net}{IPv4} (?! \d) }xms; my $S_not_IPv4 = qr{ (?! $RE{net}{IPv4}) \S }xms; ;; for my $s ( 'ADMIN__SANDRO_DESK=\"123.45.78.90\" # ilcylic Desktop', '# ADMIN__SANDRO_DESK=\"123.45.78.91\" # ilcylic Desktop (old)', '# 06/06/15 SR Chgd SANDRO 121.123.65.92', @ARGV, ) { my $match = $s =~ m{ \A $S_not_IPv4+ \s+ .* $ip }xms; printf qq{%8s '%s' \n}, $match ? 'MATCH' : 'no match', $s; } " no match 'ADMIN__SANDRO_DESK="123.45.78.90" # ilcylic Desktop' MATCH '# ADMIN__SANDRO_DESK="123.45.78.91" # ilcylic Desktop (ol +d)' MATCH '# 06/06/15 SR Chgd SANDRO 121.123.65.92'
It's a bit wordy, but still possible to express as a CLI one-liner. I think it can be said to exactly meet the stated requirements. It does so in Perl and not for grep, but that's life.


Give a man a fish:  <%-(-(-(-<


In reply to Re: Seeker of Regex Wisdom (strings which don't form specific patterns) by AnomalousMonk
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.