Solve Wordle puzzles with regular expressions
King of the Wordle
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
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.
-
Rhino Linux Announces Latest "Quick Update"
If you prefer your Linux distribution to be of the rolling type, Rhino Linux delivers a beautiful and reliable experience.