/(bb|[^b]{2})/
Sunday, December 2nd, 2007 • Related • Filed Under
…That is the question. ThinkGeek is selling that on a t-shirt for the "regular expression junkie + lover of literature." Wearing that around would be a sure way to get me to notice you, especially if you have a nice rack or happen to be Angelina Jolie.
Note that the parentheses are unnecessary except in the case of Perl-folk wishing to avoid using the naughty $&
variable for performance reasons. Also, the expression is buggy in that many alternatives to "bb" are not matched, so it would probably be better written as simply /bb|.*/s
. For a JavaScript solution you could try var answer = /^bb$/.test(i);
.
Alright, I'm done debugging the shirt now.
Comment by Azat Razetdinov on 3 December 2007:
/bb|(?!bb).*/
Comment by William "The Ownage" Bowen on 4 December 2007:
I find it funny that while you were debugging shirts I was busy debugging the pants off girls.
And I don’t even know what that means.
Comment by Steve on 4 December 2007:
Yeah, well, I was worn out from debugging your mom’s back-end.
Comment by William "The Ownage" Bowen on 4 December 2007:
That’s ok because I already checked all my code into your mom’s repository.
And I expect to be pushing some more code tomorrow night.
Comment by William "The Ownage" Bowen on 4 December 2007:
Also –
I had an atomic grouping with your mom and some friends, but her lazy repetition was not impressing me. Then when I was done she became a bit of a possessive quantifier so I finished the job with $.
Comment by William "The Ownage" Bowen on 4 December 2007:
Haha, it was a bit of a stretch. But I did come up with some more generalized geek talk ones:
Last night I inserted my Dongle into your mom’s hub but I didn’t use my Trojan.
I spent all morning servicing your mom’s asynchronous requests. On an unrelated note I heard some guy invoked the getPenis() method of your service and received a 404 status code – Not found.
I think your mom’s cache is going to need some clearing because I just filled it.
Comment by Steve on 4 December 2007:
Your mom’s repository is so old that I don’t need to use version control.
As for your regex dirty-talk, that’s just dreadful, but I’ve got nothing.
Comment by liorean on 5 December 2007:
^^ That was just dreadful!
Comment by Arthur Dent on 31 January 2008:
That’s just friggin hillarious. Myself, if I gotta debug a chick (or her clothes), she ain’t worth it.
Comment by Peter Lorre on 26 March 2008:
debugging girls?? Methinks you need to de-louse her first… creepy 😉
Comment by Eric on 28 May 2008:
/bb|.*/s and /(bb|[^b]{2})/ aren’t equivalent my friend =)
Any single-character string is matched by yours but not the original. Also any two-character string containing only one b. In fact, yours will match anything including an empty string.
It’s funny to see Azat came up with essentially the same answer I did =) Except one half of his alternation consumes while the other half doesn’t – which might be his intention, but it’s more likely you’d want both sides of the alternation to consume, or neither side to consume. That’s why I prefer /(?=bb)|(?!bb)/ (non-consuming) or /(?:(?=bb)|(?!bb))../.
This last one can be reduced to /.{2}/, but that doesn’t read quite as well =)
Comment by Steven Levithan on 28 May 2008:
No kidding. 🙂 That’s why I posted my implementation. Anything other than “bb” (including the empty string) is not “bb”. Therefore I read my regex as “two Bs or anything other than two Bs”, while I read the original as “two Bs or any two non-Bs, captured to group one”. I read your regexes here as “over-engineered, inefficient patterns that simply match any position or any two, non-line break characters.” 😛 Mine can alternatively be read as “match either ‘bb’ or the first line of the subject string.”
Comment by Z on 12 December 2008:
@ William “The Ownage” Bowen on 4 December 2007:
one word. ROFL.
Comment by Jack on 11 February 2009:
Late to the party but I was searching your blog for the answer to something… and well while y’all can fight all you want about the regex I’m going to take exception to:
var answer =
it should be:
var question =
😛
Comment by Descolada on 8 October 2011:
I’d buy this shirt if it said “String theory” on the back. ^_^
Comment by Dzzo on 26 March 2012:
@ Z on 12 December 2008:
That’s 4 words bud.