in reply to Re: Extracting IP address from large text file.
in thread Extracting IP address from large text file.
my $str = "br>94.198.240.132:60988 asdfasdf 174.142.24.201:3128 asdfas + +dfasdf"; if (my @matches = $str =~ m{ ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0- ++9]{1,3}:[0-9]{1,5}) }xmsg) { print qq{matched @matches}; }
Invalid [] range "0- " in regex; marked by <-- HERE in m/ (0-9{1,3}\.0-9{1,3}\.0-9{1,3}\.0- <-- HERE +9{1,3}:0-9{1,5}) / at C:\CC\BUY\ptest.pl line 43.
I Tried removing the enclosing () $str =~ m{ 0-9{1,3}\.0-9{1,3}\.0-9{1,3}\.0- +9{1,3}:0-9{1,5} }xmsg) = same error
I Tried adding / / $str =~ m{ /0-9{1,3}\.0-9{1,3}\.0-9{1,3}\.0- +9{1,3}:0-9{1,5}/ }xmsg) = same error
I also tried the below method with limited success.
my $str = "br>94.198.240.132:60988 asdfasdf 174.142.24.201:3128 asdfas +dfasdf"; ($p1, $p2, $p3 , $p4 , $p5) = ($str =~ /([0-9]{1,3}).([0-9]{1,3}).([0- +9]{1,3}).([0-9]{1,3}):([0-9]{1,5})/g); print "$p1 $p2 $p3 $p4 $p5 \n";
output: 94 198 240 132 60988
But does not work /g globally without some kind of looping construct.. Sigh... well there is the split the entire file into words and do it for each word method available to me now at least :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Extracting IP address from large text file.
by AnomalousMonk (Archbishop) on Oct 19, 2010 at 23:16 UTC |