in reply to How regex works in array mode?
There is no such thing as "array mode" in Perl. I believe you are refering to "list context"?
([0-9]{3}|[0-9]{2}|[0-9]{1}) could be written more simply as [0-9]{1,3} and it will also avoid the unnecessary capturing parentheses.
use strict; use warnings; my @lines = ("ip:192.168.243.1", "ip:192.168.243.2" =~ /(ip:([0-9]{3}| +[0-9]{2}|[0-9]{1})\.([0-9]{3}| +[0-9]{2}|[0-9]{1})\.([0-9]{3}|[0-9]{2}|[0-9]{1})\.([0-9]{3}|[0-9]{2}| +[0-9]{1}))/); print "@lines\n";
It looks like you want something like:
use strict; use warnings; my @lines = ( "ip:192.168.243.1", "ip:192.168.243.2" ); for ( @lines ) { print "$1\n" if /(ip:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3 +})/; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How regex works in array mode?
by astronogun (Sexton) on Apr 26, 2012 at 10:14 UTC |