in reply to Filtering out IP addresses
This appears to do what you expect, although it replaces all octets but the last with '###' (rather than based on the number of digits in the octet):
s/(([0-2]?\d{1,2}\.){3})([0-2]?\d{1,2})/###.###.###.$3/g;
Code to test regex:
$ perl -le 'foreach my $c ( q{123.45.67.89 123.45.67.98}, qw/ 0.0.0.0 +10.1.2.3 172.001.002.003 192.168.128.1 255.255.255.255 / ) { my $d = +$c; $d =~ s/(([0-2]?\d{1,2}\.){3})([0-2]?\d{1,2})/###.###.###.$3/g; p +rint $c, q{ -> }, $d; }'
Test output:
123.45.67.89 123.45.67.98 -> ###.###.###.89 ###.###.###.98 0.0.0.0 -> ###.###.###.0 10.1.2.3 -> ###.###.###.3 172.001.002.003 -> ###.###.###.003 192.168.128.1 -> ###.###.###.1 255.255.255.255 -> ###.###.###.255
Hope that helps.
|
|---|