in reply to Regex - Matching prefixes of a word
What about reversing the approach?
Instead of making a regex that matches any $word that is a prefix of 'angle', why don't use $word as a regex:
my @keywords = qw / angle offset fire torpedo /; my @match = grep $_ =~ /^$word/ @keywords;
If you previously ensured that word is a word (i.e. /\w+/), @match will give you all the keywords that partially match $word. If @match == 0, no match; if @match == 1, exact match; if @match > 1, word is ambiguous.
Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex - Matching prefixes of a word
by SuicideJunkie (Vicar) on Jul 24, 2009 at 16:41 UTC |