Regex Humor

On this page, I aim to collect all the tidbits of regex humor I manage to muster. Some of these are the fruit of well-known brilliant minds, some of it I've started to produce, and lots of it will, I hope, be contributed by you guys, who as we know are not only geniuses but also fine humorists.

There's a comment form at the bottom so please fire away. The bits that get good feedback will move to the main section of the page, and your work will get proper attribution.

Lower down there's a collection of all of Randall Munroe's xkcd strips that mention regex.[citation needed]

But first things first: what's the meaning of life?

(direct link)

The Meaning of Life

With gratitude and apologies to Douglas Adams (may he rest in peace):

"O Deep Thought computer," he said, "the task we have designed you to perform is this. We want you to tell us...." he paused, "The Answer."
"The Answer?" said Deep Thought. "The Answer to what?"
"Life!" urged Fook.
"The Universe!" said Lunkwill.
"Everything!" they said in chorus.
Deep Thought paused for a moment's reflection.
"Tricky," he said finally.
"But can you do it?"
"Yes," said Deep Thought, "I can do it. But, I'll have to think about it."
"How long?"
"Seven and a half million years," said Deep Thought.

[Seven and a half million years later.... Fook and Lunkwill are long gone, but their ancestors continue what they started]

"Good Morning," said Deep Thought at last.
"Er..good morning, O Deep Thought" said Loonquawl nervously, "do you"
"An Answer for you?" interrupted Deep Thought majestically. "Yes, I have."
"And you're ready to give it to us?" urged Loonquawl.
"I am."
"Now," said Deep Thought.
"Though I don't think," added Deep Thought, "that you're going to like it."
"Doesn't matter!" said Phouchg. "We must know it! Now!"
"Alright," said Deep Thought. "The Answer to the Great Question..."
"Of Life, the Universe and Everything..." said Deep Thought.
"Is..." said Deep Thought, and paused.
"Okay, here it is, let me print it out for you," said Deep Thought, with infinite majesty and calm.
Slowly, a narrow tape came out of a small slit in Deep Thought's titanium panels. It read:

"But… What does that mean?" asked Loonquawl.
"I don't know," said Deep Thought. "But I can design a more powerful computer that will be able to tell you that."
"It will take time, though", added Deep Thought.

1. On the following link, you can see a demo of the Meaning of Life Regex at work.
2. This page fully explains the regex… But I highly recommend you try to figure it out for yourself—it's a great exercise!
3. Authors: Douglas Adams in this book—and for the regex, Rex—7 August 2014
(to share this: direct link)

(direct link)

The Incomplete Two-Problem Quote

    (…what two problems?…)

Odds are ten to one that you've already heard the famous quote about the two regex problems. Sadly, the quote is incomplete. Jeffrey Friedl did a great job tracking down the original author Jamie Zawinski, and on my side I've been trying to find out the lost words from the complete quote. Maybe you can help.

The Original Quote:

Some people, when confronted with a problem, think
“I know, I'll use regular expressions.”
Now they have two problems.

Obviously, something there is missing… What two problems are we talking about?

Here are some attempts to complete the quote. Please send yours.

The Reversed Quote Hypothesis

Some people, when confronted with a problem, think
“I know, I won't use regular expressions.”
Now they have two problems.

Author: Rex, 21 October 2015

The Parrot Hypothesis

Sometimes, when confronted with a problem, you think
“I know, I'll use regular expressions.”
Now you have two problems:
   1. figuring out what to do with the many hours of tedious coding you just saved, and
   2. having to deal with the trolls who give you an earache parrotting some lame quote about having two problems.

Author: Rex, 7 May 2014

The Recursive Hypothesis

Some people, when confronted with a problem, think
“I know, I’ll quote Jamie Zawinski.”
Now they have two problems.

Source: Martin Liebach, March 4 2009
Variation: I think that reads better with “I know, I’ll call Jamie Zawinski.” Now they have two problems.

Will the well-meaning people of this world bring an end to this awful controversy?
People have been discussing the two-problem question quite seriously on Stack Exchange but have failed to reach a consensus. I sincerely hope that with your help, the strict scientific approach on this page will be more fruitful.

And now… A bit of regex entertainment.

(direct link)

What's the control character for "I smoke dope?"

regex bell character

Author: Rex, 8 May 2014. Source: the marvelous Regex Cookbook, 2nd Ed.

(direct link)

Password Validation

.NET password validation
It's also true in Python 3!

Author: Rex, 8 May 2014

(direct link)

Messy Editor

(Untested. Please don't use this in your code.)

Author: Rex, 8 May 2014

(direct link)

Regex Harassment

Boss: (?![0-57-9])\d[^\D0-8]\?
Employee: (slaps boss)

Author: Rex, 20 July 2014

(direct link)

Regex Humor in the Wild

This section presents tidbits of regex humor found here and there.

From Multiple Sources

Q: What did one regex say to the other?
A: .+
This one is too clever for me. I've read the explanation on Stack Overflow, but I still don't get it.

From Morten Just

Q: What regex are you most likely to see at Christmas?
A: [^L]

Q: Why couldn't Chris try out the regular expressions he created until he left home?
A: His mom wouldn't let him play with matches.

Source: mortenjust

(direct link)

xkcd regex

It seems like regex is now an official xkcd theme. It's fortunate that Randall has an on-and-off obsession with regex (if it's fair to call it that), because since you're reading this page, you probably do too.

Randall seems to have a pretty permissive license, but I'll be seeking permission to use his art here. If you like his work, consider supporting him by buying his merch. I bought his first book, xkcd: volume 0 and already look forward to What If?, named after the eponymous column.

xkcd #208: Regular Expressions
This one is my favorite (and probably everyone else's). I prefer it in this abridged form, but the link will take you to the original

xkcd 208 regular expressions

xkcd #1031: Leopard regex

xkcd 1031 regular expressions leopard regex

xkcd #1171: Perl Problems

I'm not crazy about this one, perhaps because Randall seems to be endorsing the original version of the two-problem quote, which as we've seen is sadly incomplete. But I'm probably missing the irony.

xkcd 1171 Perl Problems

xkcd #1313: Regex Golf

xkcd 1313 regular expressions

 Regex Books & More

Buy me a coffee
Buy me a coffee