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

Re: Death to Dot Star!

by Anonymous Monk
on Feb 27, 2002 at 03:21 UTC ( #147801=note: print w/replies, xml ) Need Help??

in reply to Death to Dot Star!

The last task, to match a question, can be solved quite easily by reversing the string.
my ($m) = reverse($myvar) =~ /"\?(.*?)"/s; $m = reverse $m; print "matched <$m>\n";
Note that it's OK to use .*? here. And due to optimizations in the regex engine it's even faster to use it than a negative char class, if the following pattern is constant as it is in this case.

It's also very easy to make it work for escaped quotes by adding a negative look-ahead.     my ($m) = reverse($myvar) =~ /"\?(.*?)"(?!\\)/s; Note that here you must use .*? instead of a negative char class since you want the engine to backtrack.


Replies are listed 'Best First'.
Re: Re: Death to Dot Star!
by Anonymous Monk on Feb 27, 2002 at 04:49 UTC
    you seem to have missed the point and all the nodes in this thread, not good
      I posted this as a tip to the readers of this thread. The audience is people who aren't too fluent with regexes, and the regex for matching the question is perhaps tough for beginners. I merely wanted to point out that you don't always have to use that cumbersome and easy-to-slip-with solution. And yes, I understand that it was for educational purposes.

      The task was to get rid of .*?'s in this case unwanted behaviour. That is what my solution does. I don't see why this solution doesn't fit into the thread as nicely as Ovid's regex.

      I was a bit sparse with words in my previous post, but I had no intention to devalue Ovid's node. I think it's great. I just wanted to share an idea that was applyable to the problem Ovid was solving.

      The following article is about using reverse regular expressions, or sexgers (snicker). Its purpose it to increase efficency by avoiding the lookahead mechanism. Todd W.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2023-03-29 09:11 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (70 votes). Check out past polls.