regexbashgrep

Spelling Bee game regex


In the NYTimes Spelling Bee game, you have to make words (4+ letters long) using a set of 7 letters, one of which must be used in the word. This is fairly trivial to make a regex for:

grep '^[bluntam]\{4,\}$' /usr/share/dict/words | grep u

(All lowercase to avoid acronyms and proper nouns) Is there a way to combine these into one fancy regex? The issue with putting the required letter in the center, like [bluntam]*u[bluntam]* is that there needs to be another filter to ensure the word length. I'm ok with using PCRE or any other standard bash tools.


Solution

  • How about this?

    Positive lookahead for u, then match 4+ characters?

    grep -P '^(?=.*u)[bluntam]{4,}$' /usr/share/dict/words
    

    https://regex101.com/r/7UM5Yr/2