Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Perl6: too bad non-greediness is not made the default

by Aristotle (Chancellor)
on Jul 05, 2002 at 14:37 UTC ( #179644=note: print w/ replies, xml ) Need Help??


in reply to Perl6: too bad non-greediness is not made the default
in thread Parsing with Perl 6

I try to write my regexen backtracking-free, as, I believe, anyone should. And in that case greediness is very desired and useful most of the time. Non-greediness basically means that you match broader than you really need to - it works because you "forwardtrack", you gobble the string one submatch at a time. It is better to match more narrowly and greedily, since a greedy match will gobble up a lot of the string in one fell swoop and do less superfluous searching. In simple cases the regex optimizer is smart enough to simplify a non-greedy match into a Boyer-Moore search, but when you're working with a complex regex you really want to match narrowly and greedily.

Regexen are a tricky art.

Makeshifts last the longest.


Comment on Re: Perl6: too bad non-greediness is not made the default
Re: Re: Perl6: too bad non-greediness is not made the default
by stefp (Vicar) on Jul 05, 2002 at 15:55 UTC
    I beg to differ. My general principle is to be lax on what I receive and strict on what I emit. So I try to write my regexen as lax as possible and to "synchronize" my match on characters/sequences I am sure will be present in the input. This means that I often use .*? in my regexen. Using the greedy counterpart will lead to a lot of backtracking and more so geometrically with the number of .*?. Also I incrementally build my regexen testing them on samples: non greedy match also is less a nuisance here when examining the matches.

    Regexen are a tricky art and I like to abuse it at (*) the risk of being called demented. (*) And I beg to disagree with Felix Gallo, France is the lang of semiology, not of semiotics... and hair splitting too, BTW. And, on a related field, the main tagmemics foray in France is collateral to the introduction of american camelides but has yet to appear widely in French. tagmemique is indeed French neologism that googlewhacks until the present node referencing of a node

    -- stefp (qui aime couper les cheveux en quatre)-- check out TeXmacs wiki

      Each to his own, I guess. :)

      Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2014-07-10 18:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (215 votes), past polls