Cheating at Bee with RegEx

Spelling Bee

We often get questions about using RegEx on XWord Info, most of which I can’t answer, but an intriguing question arose recently. Can RegEx be used to find NYT Spelling Bee words?

The short answer is that, yes, we you can filter words in our lists that match Bee rules, but you end up with a lot of crap — phrases, foreign words, proper nouns, roman numerals, etc. — none of which are allowed in the Bee.

Still, it’s an interesting question, and a good chance to dig into RegEx arcana. Let’s take today’s puzzle as an example.

The Bee always includes seven letters. Today’s set: A D E H I N P. So, we start by finding words that contain only those letters. There’s a similar example in the Instructions, so this one is easy. (You can click each example here to see the results on XWord Info.)

Regex: ^[ADEHINP]+$

This is already useful! All the Bee words are already there, but it would be nice to filter out as much crap as possible. For one thing, words must be at least four letters long. You can specify {minimum length, maximum length}. Ignore maximum because we don’t care how long the word is. This modification will do the trick:

Regex: ^[ ADEHINP ]{4,}$

Better, but we’re missing the most important detail! Every Bee has a central letter that MUST be included in the answer. In this case, the key letter is A, so let’s ignore words that don’t include A.

For this, we need two conditions, the one above AND the one that requires an A. In order to AND two conditions, we need to take advantage of a RegEx feature called Lookahead. There might be a better way to do this (I’m not a RegEx expert) but here’s my solution:

Regex: (?=^[ADEHINP]{4,}$)(?=.*A.*)

As noted earlier, still a lot of crap, but that’s the best we can do for now. Maybe I should add a BEE button to the Finder page that only looks in dictionaries, not crossword lists? Because, you know, there aren’t already enough options there.

You can use this logic to scan your own lists by writing a simple Python script.

1 comment

Your thoughts?