http://www.perlmonks.org?node_id=905194


in reply to Re: regex for word puzzle
in thread regex for word puzzle

Assume your rack is rtesamcna. Assume also you have the list of valid words in TWL.txt. The following grep command will show you words formed using only letters in your rack, but it will use any number of the letters:

grep -i '^[rtesamcna]*$' TWL.txt

Not quite what you want. You don't want words with more than 1 R, or more than 2 A's. So we filter it out:

grep -i '^[rtesamcna]*$' TWL.txt | grep -iEv 'r.*r|t.*t|e.*e|s.*s|a.*a.*a|m.*m|c.*c|n.*n'

And finally, to show anything with at least 9 letters:

grep -i '^[rtesamcna]*$' TWL.txt | grep -iEv 'r.*r|t.*t|e.*e|s.*s|a.*a.*a|m.*m|c.*c|n.*n' | grep ...... +...