The English word balloon has two consecutive double-letter pairs (ll and oo). Are there any English words with four consecutive double-letter pairs? This can be a real stumper for someone who doesn’t know regular expressions. But with regexes, it’s easy:

grep -E '(.)\1(.)\2(.)\3(.)\4' /usr/share/dict/words

Some explanation about that command:

  1. grep is a command that searches stuff. It was named after a similar command in the old ed editor, g/re/p, for global regular expression print.

  2. The -E flag tells grep to use extended regular expressions, which are strictly more powerful than formal regular expressions.

  3. words is a standard Unix file, though its exact location and contents are not standardized. I’m writing this on an old-ish version of MacOS. Your system may have a different words file, and in particular it may have one without the word subbookkeeper.1

  4. The single quotation marks '' serve to delimit the regex string to be passed to grep. Double quotation marks "" can also be used, but they are probably the wrong choice, since they allow shell evaluation inside.2

  5. The meat of the command, of course, is the regex (.)\1(.)\2(.)\3(.)\4. It consists of three basic parts:

    • The dot character . matches any character at all in a string. If the words file contained numbers and punctuation and other junk, this would be a bad choice, and something more specific would be needed.
    • The parentheses () group whatever is inside them. A grouped match can be referenced later.
    • The backslash-numbers \1 etc are backreferences. This is how grouped matches can be referred back to. The nth backreference refers to the nth match (with the numbering typically being 1-indexed).

I like to grep dictionaries for different patterns. For instance, here’s one to search for words with palindromic substrings of length eight or nine:

grep -E '(.)(.)(.)(.).?\4\3\2\1' /usr/share/dict/words

This yields some good ones, like sensuousness, leviative, and overappareled. Note the presence of the question mark ? in that regex: it means that the preceding match can occur once or not at all. This is needed because abcba and abba are equally palindromic.

That search can be modified to yield strict palindromes by adding the caret ^ and dollar sign $, which respectively match to the beginning and end of a string. Wrapping a regex in ^$ will match only whole strings, not substrings.

grep -E '^(.)(.)(.).?\3\2\1$' /usr/share/dict/words

This gives words like reviver, rotator, and my favorite, repaper.

As a challenge, consider the following search:

grep -E "(.).\1..\1...\1....\1" /usr/share/dict/words

How would you characterize that regex in plain language? Can you think of a match?

But enough about English. It’s also fun to grep other languages for strange patterns. Let’s take Turkish, for example. First, we need to get a Turkish word list. One way to do this is:

curl --silent | grep -v '[ ]' > ~/turkish-words

Let’s try the search we started with, looking for words with four consecutive double-letter pairs.

grep -E '(.)\1(.)\2(.)\3(.)\4' ~/turkish-words

This is an archaic Turkish word meaning unfortunately. A commonly-used variant is maalesef. Both are ultimately derived from the Arabic word asef اسف, meaning regret or something like that.

How about palindromes? It turns out that Turkish actually has a full nine-letter proper palindrome:

grep -E '(.)(.)(.)(.).?\4\3\2\1' ~/turkish-words

The word kama means dagger, and -mak is a verbal infinitive suffix, so kamalamak is a verb meaning to stab with a dagger, or even just to dagger if you want to use dagger as a verb.

Another fun application is finding what I call Turkish keyboard words. A typical Turkish keyboard looks a lot like an American QWERTY keyboard, except that it has six extra letters added to the right of m l p: ö ç ş i ğ ü.3 I like to try and think of words and phrases that can be written using only these letter (along with spaces). Finding such words is easy with regexes.

grep -E '^[öçşiğü]+$' ~/turkish-words

These words can be shuffled around to make funny phrases like üç öç iği, three revenge spindles, and çiğ işçi çişi, raw worker piss.

Now let’s take a look at some Georgian words. Again, we’ll need a word list first.

curl --silent -o ~/ && unzip ~/ -d ~/ka-crubadan && awk '!/-/ { print $1 }' ~/ka-crubadan/ka-words.txt | LC_ALL=C sort -d > ~/georgian-words

Georgian is infamous for its difficult consonant clusters. The Georgian vowels are ა ე ი ო უ (a e i o u), so let’s try grepping for words with sequences not containing those letters. To do this, we’ll use bracket-caret notation: [^a], for example, matches characters other than a. For convenience, we’ll also use brace counting: a{5} matches five a’s in a row.

grep -E '[^აეიოუ]{6}' ~/georgian-words

The first eleven words in that list are obvious variations of მწვრთნელი trainer, coach. 4 Transliterated into English, this word looks like mtsvrtneli (with the single letter წ transliterated as ts). To say the least, it’s not an easy word to say.

The only word in that list that isn’t a variation of მწვრთნელი is შორსმჭვრეტელი seer (I think). The regex matched this word on the substring რსმჭვრ rsmchvr. This is actually a compound word – შორს far and მჭვრეტელი watcher – so in a linguistic sense this probably doesn’t count as a true consonant cluster. But this isn’t a post about linguistics, it’s a post about grepping.

Finally, consider the Georgian letter . This letter stands for a sound that is very foreign to English, a pop from the back of the throat. It corresponds to the Arabic ق. A word that Georgians often trot out to mock the pronunciation of foreginers is ბაყაყი frog. This has two ყ’s in close proximity, and it’s hard to get it right. Curiously, this word is of Turkic origin, and variations are used all over the place – Sorani Kurdish, for instance, has بۆق.

Anyway, are there any other Georgian words with ყ’s near each other?

grep -E 'ყ.?ყ' ~/georgian-words

Excluding variations, it looks like there are just two other words with this pattern: ყაყაჩო poppy and ყოყმანი hesitation. They are also hard to say.


1 Is a words file (or a dictionary in general) better or worse for having a somewhat artificial word like subbookkeeper? If your words file doesn’t have this word, do you wish it did?

2 On my computer, the command grep "$USER$" /usr/share/dict/words yields words like picknick. Can you guess what my username is?

3 The usual i key is actually replaced with the Turkish dotless ı, so that when Turkısh people wrıte emaıls ın Englısh, ıt sometımes looks lıke thıs.

4 The twelfth word, სამწვრთნელო, is a non-obvious variation: სა-მწვრთნელ-ო. I think it means gym or training facility.