tags:

views:

2468

answers:

10

I love regex. I’ve used them with grep, Perl, Java, C, and a variety of others. I have Jeffery Friedl’s awesome book on them, and I studied their theory in college.

But for years I have been haunted by a famous regex joke:

Q: What did one regular expression say to the other?

A: .*

which I first saw on Slashdot, years ago.

Could someone conclusively explain this one to me? I have seen this joke time and time again, but despite fully understanding regular expressions I do not get the punch line.

+10  A: 

".*" matches everything. Other than that, I don't know what to tell you, it's not a very funny joke.

Paul Tomblin
+14  A: 

Maybe it means, whatever one regular expression said to another, it would be matched by .*

alex
+3  A: 

Maybe the joke is that regexes can't speak? I can't find anything else funny in there....

joeslice
+2  A: 

Supposed to represent emoticons??

See: http://turing.cs.camosun.bc.ca/CompTech/index.php?topic=389.0

Michael Bray
The people on that page are so clueless it's not even funny.
Paolo Bergantino
I had looked at that page while researching this question, read one of the answers on that page, and thought for a fleeting moment that I was utterly crazy and had forgotten what "." matched. Sadly no, that page offered no answers either.
Kevin L.
+38  A: 

Best translated as "Whatever!" (a common one-word occurrence in alleged "conversation" in certain age groups).

Alex Martelli
Normally, explaining a joke sucks the fun out of it, but the qq/alleged "conversation"/ part made me ROTFLOL. My co-workers are looking at me funny. +++++
Massa
+2  A: 

Note that usually the dot does not match everything. Think about newlines. In order to match those, you will need to enable “dot-matches-all” mode. In Perl and PCRE a /s modifier is available for that.

Geert
ahhh geeks, gotta love em! ;-)
Si
And how, pray tell, does one use a newline in spoken conversation?
intuited
@intuited I tend to let people I'm talking to know I'm speaking a new line through the medium of interpretative dance.
Zeus
@Zeus: that was a new line right there.
intuited
+15  A: 

A typical exchange among adolescent regexes:

//          # What's up, dude?
/.*/        # Whatever!  (#)
! /./       # Not!
/[#!%$&*]+/ # Screw you!

(#) Borrowing Alex Martelli's fine answer.

FM
+1  A: 

it says... WHATEVER xD

since the * denotes any char alphanumeric in regex...

thanks for the funniest problem ever

Ahmad Dwaik
+1  A: 

What about this:

Since the question specifically reference two regexes ('one' and the 'other') - you could interpret it this way:

Regex one=/Q. What did one regex say to the other?/ 
Regex other=/.*/

Which could (weakly I admit and still not funny) make the answer :

'What did one regex say to the other?' (since '.*' would match the first regex).

Which would make it a bit like the famous 'Who's on first base?' joke...

OR perhaps:

Regex one=/Q. What did one regex say to the other? A. .*/
Regex other=/Q. What did one regex say to the other? A. .*/

That is , apply the whole thing as a regex, run against itself..which would make it a infinite recursion joke for which there is a known tradition (especially in acronynms such as 'GNU')...

And a bit like those birthday cards which have 'how to confuse an idiot, turn over': which upon doing so reveals the same message....

The weakness in the above explanations is that even though the question is a valid regex, just not a very likely one: the first explanation doesn't even really use it as a regex (just a string) and then second explanation possibly suffers from ambigiouty as it contains a '?'...

monojohnny
Also, the second example is cheating since the NLs have had to be chomped to make '.' work...(see earlier posting about Perl 'dot-matches-all'...
monojohnny
A: 

It's like when Cliff Claven was on Jeopardy and the final jeopardy answer was something that, despite having accumulated a ridiculous sum of money (all of which he had bet on that question) he was unable to answer. The question —well, answer— matched /^These three people \w+ed the .*./. He wrote, "Who are three people who have never been in my kitchen?"

intuited
I had to use Google to get the reference, for I am woefully uncultured in the area of *Cheers* : http://en.wikipedia.org/wiki/What_is..._Cliff_Clavin%3F
Kevin L.
Wow, it's Wikified. That's good, I got some details wrong.
intuited