Your skill will accomplish what the force of many cannot |
|
PerlMonks |
Re: Seeker of Regex Wisdom (strings which don't form specific patterns)by AnomalousMonk (Archbishop) |
on Aug 13, 2015 at 11:58 UTC ( [id://1138416]=note: print w/replies, xml ) | Need Help?? |
... 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 The requirements [one or more whitespace chars] and [zero or more chars] are exactly met by \s+ and .* respectively.
For 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: 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 Section
Seekers of Perl Wisdom
|
|