in reply to Filtering out IP addresses

It might be fun to write regular expressions but it's also reinventing the wheel. Regular expressions for IPs can be found in Regexp::Common.

perl -MRegexp::Common='net' -n -e 'm/$RE{net}{IPv4}{-keep}/ && print "xxx.xx.xx.$5\n"'

Replies are listed 'Best First'.
Re^2: Filtering out IP addresses
by BillKSmith (Monsignor) on Jul 23, 2014 at 04:17 UTC
    Great idea. Let's generalize to respect the length of each field and make the substitutions in the original text.
    use strict; use warnings; use Regexp::Common qw /net/; my $string ='194.66.82.11'; $string =~ s/$RE{net}{IPv4}{-keep} /'x'x(length $2) . '.' . 'x'x(length $3) . '.' . 'x'x(length $4) . '.' . $5 /xge; print $string;
    Bill

      Great idea. Let's generalize to respect the length of each field and make the substitutions in the original text.

      Not matching the original field lengths may actually be a feature here - you'd be providing extra information if you did, which may or may not be what you want.