in reply to RegEx Array
Note that I changed the conditional in the foreach loop so that it would print only if the match was successful rather than in $1 was defined, which in this case after the first match continues to be defined.#!/usr/bin/perl -w use strict; my $string = "Field1: one"; my @regex; push(@regex, qr/Field1: (\w{3})/); push(@regex, qr/Field2: (\w{3})/); push(@regex, qr/Field3: (\w{3})/); foreach (@regex) { if ($string =~ $_ ) { print "$1\n"; } }
-enlil
|
|---|