I was tackling this kind of thing a lot when people would keep posing the "how
do I match a C comment?" back in the early days Pre-Ilya-RE. I got pretty good
at breaking just about any regex that claimed to match a comment, by undoing
any assumption made.

Rather than simply testing for a question mark followed by a character that is not a quote (\?[^"]), I should have tested for a question mark with a negative look-ahead (\?(?!")) for a quote. This appears to work:

Unfortunately, Benchmark shows that it's not quite as fast as merlyn's version.

For those unfamiliar with lookaheads, they allow you to test for text without "bumping along" the regex. In other words, \?[^"] will check for a question mark followed by a non-quote character, but further matching of the regex continues after the non-quote character. \?(?!") allows you to check for a question mark not followed by a quote, but continues matching after the question mark.

Note: There is a subtle difference between the negated character class and the negative lookahead. The negated character class generally requires a character after the question mark (in the above example), while the negative lookahead just makes sure that a quote doesn't follow the question mark and doesn't require a character.

Okay, the title is kind of a joke. It's just a good-natured tweak at merlyn for the brouhaha over his WARNING t0mas wrote BAD CODE node that generated so much flak. No offense intended :)

merlyn's code was bugging me, but I couldn't quite put my finger on it. My problem was that the dot metacharacter is so indiscriminating that it will match anything. However, I simply assumed that if merlyn posted the code, it must work. His code is great if you're checking for C-style comments that begin and end in something like /* comment here */ or "? comment here ?". But if you read my post, that's not what we were checking for:

What happens if you were trying to extract questions in quotes without the trailing question mark?

I mentioned embedded question marks (my idea was that we might have more than one question in a quote), but I never mentioned embedded quotes. I just wanted one set of quotes and my original post bears that out. Here's merlyn's code and my correction:

I misunderstood the goal, but I knew that yours wouldn't solve the goal. :)

Typical Randal. Hey, Randal, have you ever thought about just acknowledging someone else's effort without taking a swipe at the bloke afterwards? I mean, really, how many times do we have to put up with you acting like the big dog and pretending that no one else has anything else to offer?

I've read through some of your posts here and I have never seen you compliment anyone. On this one, you could have just admitted you were wrong and complimentd "ovid" on his code, or just admitted that you were wrong. Period. No, your ego wouldn't allow that. You had to cut him down.

If you even remotely care about why you have problems with people, perhaps you should wonder why you cannot be bothered to acknowledge anyone. You know why the witch hunt at Intel and your felony conviction happened? It is not because you were wrong. It looks like you were trying to act in the company's best interest. It's because you are so arrogant that people want to take you down a peg.

When putting a smiley right before a closing parenthesis, do you:

Use two parentheses: (Like this: :) )
Use one parenthesis: (Like this: :)
Reverse direction of the smiley: (Like this: (: )
Use angle/square brackets instead of parentheses
Use C-style commenting to set the smiley off from the closing parenthesis
Make the smiley a dunce: (:>
I disapprove of emoticons
Other