in reply to First Pattern Matching
#!/usr/local/bin/perl -w use strict; my @pattern = ('B.B', 'CB'); my $re = qr/^(.*?)(?:@{[ join "|", map "($_)", @pattern ]})/; foreach (qw(ABCBXBCA APCBXBCAC)){ if(my ($keyword,@match) = /$re/) { my $i = 0; $i++ until defined shift @match; print "String:$_ Pattern:$pattern[$i] KeyWord:$keyword +\n"; } }
The key is that I capture separately for each pattern.
Update: per jryan's point, edited to generate the regex once before the loop.Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: First Pattern Matching
by Anonymous Monk on Jul 11, 2002 at 23:56 UTC |