Perl Monk, Perl Meditation | |
PerlMonks |
Re: Seeker of Regex Wisdom (strings which don't form specific patterns)by kcott (Archbishop) |
on Aug 12, 2015 at 20:38 UTC ( [id://1138344]=note: print w/replies, xml ) | Need Help?? |
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:
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:
— Ken
In Section
Seekers of Perl Wisdom
|
|