Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://24685]
help
Chatterbox?
[stevieb]: I'm learning that no matter how good a piece of software is at what it's supposed to do, it's a piece of shit without providing any API documentation. (Talking about C++ here currently). Seriously... write software for an embedded platform and make...
[stevieb]: ...you guess based on the sparse examples, and the header files that are spread out illogically?

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2017-05-28 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?