Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by Ovid (Cardinal)
on Jul 27, 2000 at 19:37 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-04-23 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found