[plug] scrabble regex

Ryan ryan at is.as.geeky.as
Thu Jun 19 22:43:42 WST 2003


On Thu, 2003-06-19 at 21:55, David & Lisa Buddrige wrote:
> My problem is, I can't figure out how to match only one instance of each
> letter that I specify.  For example, If I have the letters "o" and "l", it
> picks up "loo" or if I have "nacot", it will pull out "cannot" even though I
> only have one "n".
> 
> I have tried the following regex's:
> 
> ^([letters]){2,num-letters}$
> 
> and
> 
> ^[letters][letters][letters][letters]$
> 
> but I still have the problem of using a letter more than once...
> 
> Does any one know how to define a regex that matches a letter from a list of
> letters only once ?

I don't know about _one_ regex for that, it would be 'nice' ... but
large complicated regexes alone are not the answer to everything, not
that I'm in any position to be authoritive on this matter :)

Try a 'countdown' looping the characters through a very simple
substitution regex:

http://www.perlmonks.org/index.pl?node_id=138568

It is not tremendously efficient, it knocks the letters off each word
from the dictinary, if there is nothing left at the end, you've found
your word(s).  I've used it for other purposes and it works fine.

Once you understand how it works, read this for fun:

http://www.perlmonks.org/index.pl?node=%22Countdown%22%20%28golf%29

Ryan



More information about the plug mailing list