in reply to How to define a list of regular expressions?
Remember, however, that Perl's | (vertical bar) regex alternation operator provides ordered alternation: the overall alternation will match with whatever sub-pattern first matches in the alternation sequence, regardless of length. See Matching this or that in perlretut.>perl -wMstrict -le "my @regexes = ( qr{ foo }xms, qr{ bar }xms, qr{ baz }xms, ); my $any_regex = qr{ @{[ join '|', @regexes ]} }xms; for my $file (@ARGV) { print $file, $file =~ $any_regex ? ' MATCHES' : ' no match'; } " xfooy snork bar xfooy MATCHES snork no match bar MATCHES
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to define a list of regular expressions?
by poolpi (Hermit) on Jul 02, 2009 at 07:32 UTC |