Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: regexp to grab STRING...[everything here]...DIF STRING

by AnomalousMonk (Canon)
on Oct 25, 2012 at 23:23 UTC ( #1000963=note: print w/replies, xml ) Need Help??

in reply to regexp to grab STRING...[everything here]...DIF STRING

Just a cautionary example of greedy  .* versus lazy  .*? regex matching:

>perl -wMstrict -le "my $s = 'xx FOR foo IN bar baz and FOR fee fie foe IN fum yy'; ;; my @for_in = $s =~ m{ FOR .* IN }xmsg; printf 'greedy: '; printf qq{'$_' } for @for_in; print ''; ;; printf 'lazy: '; @for_in = $s =~ m{ FOR .*? IN }xmsg; printf qq{'$_' } for @for_in; " greedy: 'FOR foo IN bar baz and FOR fee fie foe IN' lazy: 'FOR foo IN' 'FOR fee fie foe IN'

Also note that in the conditional statement
    if (my @captures = $string =~ m{ pattern }xmsg) {
if nothing matches (no captures, array empty), the conditional evaluates false and the statement body is not executed.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000963]
choroba having "blue pipeline duty" this week
[Corion]: choroba: Exactly that, but I prefer to keep an eye on my mood nowadays...
[Corion]: Also, there's one colleague who wants to join a well-established weekly telco, and I'm not convinced of the use there...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2017-03-29 07:35 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (344 votes). Check out past polls.