[plug] scrabble regex

Bernard Blackham bernard at blackham.com.au
Thu Jun 19 23:26:09 WST 2003


On Thu, Jun 19, 2003 at 09:55:31PM +0800, David & Lisa Buddrige wrote:
> 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?

Hmmm. You could do it for one letter at a time and then chain these
together...  eg, for dog:

/^[^d]*d[^d]*$/ && /^[^o]*o[^o]$/* && /^[^g]*g[^g]*$/ would only
match dog, god, odg, ogd, dgo, gdo, but not good.

This would fail for when you did infact want repeat letters in a
word, eg, good, you'd need to use /^([^o]*o){2}[^o]*$/.

The other suggestions on the list might be more usable. Just a
thought :)

Regards,

Bernard.

-- 
 Bernard Blackham 
 bernard at blackham dot com dot au



More information about the plug mailing list