Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Death to Dot Star!

by Anonymous Monk
on Feb 27, 2002 at 03:21 UTC ( [id://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.

-Anomo

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.

      -Anomo
      The following article is about using reverse regular expressions, or sexgers (snicker). Its purpose it to increase efficency by avoiding the lookahead mechanism. http://www.perl.com/pub/a/2001/05/01/expressions.html Todd W.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2024-03-19 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found