Solve Wordle puzzles with regular expressions
King of the Wordle

© Lead Image © lightwise, 123RF.com
Five letters, one word, six tries – that's Wordle. You can solve any Wordle in just a few steps and gain practical experience using grep and regular expressions.
You've probably come across strange posts on various social media platforms recently where users have shared images of what at first glance appears to be a very simple word game. Typically, you'll see a grid of five by six boxes colored either gray, yellow, or green populated by five-letter words that don't seem to have anything in common.
If you've steered clear of the hype so far, this phenomenon goes by the name of Wordle [1]. Launched in October 2021, the free and currently ad-free Wordle was quickly acquired by The New York Times Company from US software developer Josh Wardle for a "low seven-figure sum" – rumors on the web claim the actual sum was $6 million [2].
To solve Wordle puzzles, you need an extensive vocabulary. If you want to make things a little easier, you can use a dictionary file and some regular expressions and create your own Wordle solver. From an IT point of view, Wordle offers an ideal practical example for getting started with grep
and regular expressions.
Numerous Wordle Clones
All the hubbub about Wordle and the game's simple structure have already prompted numerous developers to program clones. In addition to various web-based imitations, there are also apps for mobile operating systems such as Android and iOS. There are even native Wordle imitators for Linux, such as Warble [3]. Like the original, all of these applications use an English-language dictionary (Figure 1).

The easiest approach to implementing a Wordle game is probably via the command line because the game does not need complex graphics. For Linux, an open source Wordle [4] (Figure 2) can be downloaded with a few simple commands (Listing 1).
Listing 1
Wordle in the Terminal
01 $ wget https://github.com/ivanjermakov/wordle/releases/latest/download/wordle 02 $ chmod +x wordle 03 $ ./wordle

In addition to clones, sites such as The Word Finder [5] or Wordle Solver [6] can help you find a solution (the source code for Wordle Solver is available on GitHub [7]).
Basics of the Game
To solve a Wordle, you don't have to learn complicated rules. You have six attempts at each Wordle. In the first step, just enter an arbitrary five-letter word in the top line. On your first attempt, there are no clues; your first guess is completely random.
After pressing Enter, Wordle checks the input. If a field lights up green, the letter you entered is correct and is in the right place. If the field shows up yellow, the letter is part of the word, but currently in the wrong place. A letter with a dark gray background, on the other hand, is not part of the target word. With the help of these hints, you can narrow down the target word in the following lines until all of the letter fields light up green and you have solved the Wordle. You have a total of six attempts (Figure 3); there is always only one Wordle a day (see the "Second Chance" box).
Second Chance
Wordle usually only lets you play once a day. Instead of implementing this function via an account system, the providers simply set a cookie in the browser that identifies the user. If you are not worried about your statistics, you can simply delete the corresponding cookie and have another go at discovering the word of the day. To manage the cookies stored by the current website (e.g., in Chrome), click on the lock icon to the left of the address bar and select Cookies from the menu that then opens. Then select the cookies for the page and press Remove. Reload the page by pressing F5 to restart the game. However, this still only leaves you with one search term a day.

Using Regexes
You can solve a Wordle using the Linux grep
tool and a couple of simple regular expressions (regexes), which can be used to automatically process and filter texts and strings. If you have not worked with these tools previously, they are indispensable in the everyday life of software developers. Using these tools to solve a Wordle is a wonderful introduction to this topic with huge practical benefits. To solve a Wordle, we will work our way through the hints step by step, and at the end the computer will output the solution.
For this to work, however, you first need a dictionary. A dictionary may not exist on your Linux system, but check out /usr/share/dict/
first – you might find a file that fits the bill. For a word list, you will use words_alpha.txt
, which you can get from GitHub [8]. This lists contains over 370,000 words, including some pretty quirky ones, as you'll see later.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.
News
-
Zorin OS 17 Beta Available for Testing
The upcoming version of Zorin OS includes plenty of improvements to take your PC to a whole new level of user-friendliness.
-
Red Hat Migrates RHEL from Xorg to Wayland
If you've been wondering when Xorg will finally be a thing of the past, wonder no more, as Red Hat has made it clear.
-
PipeWire 1.0 Officially Released
PipeWire was created to take the place of the oft-troubled PulseAudio and has finally reached the 1.0 status as a major update with plenty of improvements and the usual bug fixes.
-
Rocky Linux 9.3 Available for Download
The latest version of the RHEL alternative is now available and brings back cloud and container images for ppc64le along with plenty of new features and fixes.
-
Ubuntu Budgie Shifts How to Tackle Wayland
Ubuntu Budgie has yet to make the switch to Wayland but with a change in approaches, they're finally on track to making it happen.
-
TUXEDO's New Ultraportable Linux Workstation Released
The TUXEDO Pulse 14 blends portability with power, thanks to the AMD Ryzen 7 7840HS CPU.
-
AlmaLinux Will No Longer Be "Just Another RHEL Clone"
With the release of AlmaLinux 9.3, the distribution will be built entirely from upstream sources.
-
elementary OS 8 Has a Big Surprise in Store
When elementary OS 8 finally arrives, it will not only be based on Ubuntu 24.04 but it will also default to Wayland for better performance and security.
-
OpenELA Releases Enterprise Linux Source Code
With Red Hat restricting the source for RHEL, it was only a matter of time before those who depended on that source struck out on their own.
-
StripedFly Malware Hiding in Plain Sight as a Cryptocurrency Miner
A rather deceptive piece of malware has infected 1 million Windows and Linux hosts since 2017.