fletcher_the_dog has asked for the wisdom of the Perl Monks concerning the following question:
The last names have been changed to protect the innocent :-) In my real code there are about 15 last names I am looking for. This regex works fine, My question is: Is there a more efficient way to check for one of the last names than to enumerate them like I have done? Obviously, I will have to enumerate them somewhere, but it seems like my regex is rather inefficient as it has to walk through a long list. I have tried to think of a way to incorporate some kind of hash look up into the regex, but I couldn't figure out a way to do it.foreach my $name ($text=~/(\b(?:[A-Z](?:\.|[a-z]+)\s+)+(?:Jones|Rogers +|Edwards|Smith|Jackson))/sg){ print $name."\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Efficiency in regex
by Paladin (Vicar) on Dec 28, 2002 at 03:00 UTC | |
by waswas-fng (Curate) on Dec 28, 2002 at 03:16 UTC | |
by jryan (Vicar) on Dec 28, 2002 at 04:10 UTC | |
by fletcher_the_dog (Friar) on Dec 30, 2002 at 15:25 UTC | |
|
Re: Efficiency in regex
by Zaxo (Archbishop) on Dec 28, 2002 at 03:51 UTC | |
|
Re: Efficiency in regex
by bart (Canon) on Dec 28, 2002 at 16:52 UTC | |
|
Re: Efficiency in regex
by gmpassos (Priest) on Dec 28, 2002 at 18:09 UTC |