Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

(Ovid) RE(2): Death to Dot Star!

by Ovid (Cardinal)
on Jul 27, 2000 at 19:37 UTC ( #24685=note: print w/ replies, xml ) Need Help??


in reply to RE: Death to Dot Star!
in thread Death to Dot Star!

Drat, drat drat! And I was on a roll :) Nice work.

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:

$myvar =~ /"((?:[^?"]|\?(?!"))*)\?"/';
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.

Cheers,
Ovid


Comment on (Ovid) RE(2): Death to Dot Star!
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://24685]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2014-10-25 09:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (142 votes), past polls