in reply to Regex host portion of IPv6 address
My suggestion ( tested)
my $infile = "try.txt"; open my $INFILE, q{<}, $infile or die; my $outfile = "results.txt"; open my $OUTFILE, q{>}, $outfile or die; while (my $line = <$INFILE>){ $line =~ s/\s+$//; print STDOUT "the line is $line\n"; #if ($line =~ /(\d+):(\d)::\/(\d+)/){ if ($line =~ /(\d+):(.*)\/(\d+)/){ print $OUTFILE "the first decimals are $1\n"; print $OUTFILE "the last decimals are $3\n"; print $OUTFILE "the middle element is $2\n"; } print $OUTFILE "\n"; } close $INFILE; close $OUTFILE;
In $1: you have 2001
Perl understands the ":" in the regex
in $2, you have 1:: or 0:6:4003:: or :12
in $3, you have 64 or 128
Hope it helps !Here are the reuslts
the first decimals are 2001 the last decimals are 64 the middle element is 1:: the first decimals are 2001 the last decimals are 64 the middle element is 0:6:4003:: the first decimals are 2001 the last decimals are 128 the middle element is :12
|
|---|