H
Hal Vaughan
I've been reading the FAQ on Regexes and I see I can map to create an array
of patterns to be found in a Regex, like this:
@patterns = map { qr/\b$_\b/i } qw( foo bar baz );
LINE: while( <> ) {
foreach $pattern ( @patterns ) {
print if /\b$pattern\b/i;
next LINE;
}
}
And the next example talks about backtracking, as well.
I think I remember, at some point, reading how it was possible to specify an
array or hash in a regex to see if one or more of multiple matches were
found, someting like:
@pattern = qw(foo bar baz);
if ($line =~ /@pattern/) {print "Found a match!\n";}
I KNOW that does not work, as is, but I've been trying to find out if there
was something similar using an array or hash to check multiple values. I
thought I remembered also being able to do something like:
@pattern = qw(fooba? f.*?bar);
(@found) = $line =~ /@pattern/);
Which would find all the matches for both regexes specified in @pattern and
put them all in @found.
Is this possible? Is there some way, other than interating through a loop,
to match multiple patterns?
Thanks!
Hal
of patterns to be found in a Regex, like this:
@patterns = map { qr/\b$_\b/i } qw( foo bar baz );
LINE: while( <> ) {
foreach $pattern ( @patterns ) {
print if /\b$pattern\b/i;
next LINE;
}
}
And the next example talks about backtracking, as well.
I think I remember, at some point, reading how it was possible to specify an
array or hash in a regex to see if one or more of multiple matches were
found, someting like:
@pattern = qw(foo bar baz);
if ($line =~ /@pattern/) {print "Found a match!\n";}
I KNOW that does not work, as is, but I've been trying to find out if there
was something similar using an array or hash to check multiple values. I
thought I remembered also being able to do something like:
@pattern = qw(fooba? f.*?bar);
(@found) = $line =~ /@pattern/);
Which would find all the matches for both regexes specified in @pattern and
put them all in @found.
Is this possible? Is there some way, other than interating through a loop,
to match multiple patterns?
Thanks!
Hal