Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

regexp /gs oddity or bug

by Anonymous Monk
on Apr 22, 2002 at 08:36 UTC ( #161015=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Might someone explain this little oddity.
$_ = "is this odd or not?"; @a = /(.*? )/gs; # note the ? is followed by a space print "@a";

It only gives one match here (5.6.1, linux). With only /g it matches multiple times. It also matches multiple times with /gsi, but not with combinations of /gs and other modifiers. It does multiple matches if you replace the trailing space in the re with a \s though.

Comment on regexp /gs oddity or bug
Download Code
Re: regexp /gs oddity or bug
by Joost (Canon) on Apr 22, 2002 at 09:58 UTC
    Looks like a bug to me, also perl 5.7.3 on linux (latest beta i've got installed here) WILL match multiple times on your code.

    Joost.

Re: regexp /gs oddity or bug
by bjelli (Pilgrim) on Apr 22, 2002 at 09:59 UTC
Re: regexp /gs oddity or bug
by argathin (Acolyte) on Apr 22, 2002 at 10:06 UTC
    Just as another datapoint: Perl 5.6.1 on Solaris ("sun4-solaris") gives the same result as described in your post.
Re: regexp /gs oddity or bug
by TheHobbit (Pilgrim) on Apr 22, 2002 at 10:30 UTC

    Hi,
    I ran your code with a use re "debug"; at the beginning and here is what I got:

    Compiling REx `(.*? )' size 10 first at 5 1: OPEN1(3) 3: MINMOD(4) 4: STAR(6) 5: SANY(0) 6: EXACT < >(8) 8: CLOSE1(10) 10: END(0) floating ` ' at 0..2147483647 (checking floating) anchored(SBOL) impli +cit minlen 1 Guessing start of match, REx `(.*? )' against `is this odd or not?'... Found floating substr ` ' at offset 2... Guessed: match at offset 0 Matching REx `(.*? )' against `is this odd or not?' Setting an EVAL scope, savestack=6 0 <> <is this odd > | 1: OPEN1 0 <> <is this odd > | 3: MINMOD 0 <> <is this odd > | 4: STAR Setting an EVAL scope, savestack=6 SANY can match 2 times out of 2... 2 <is> < this odd > | 6: EXACT < > 3 <is > <this odd > | 8: CLOSE1 3 <is > <this odd > | 10: END Match successful! Guessing start of match, REx `(.*? )' against `this odd or not?'... Not at start... Match rejected by optimizer Freeing REx: `(.*? )'

    Looks like it actualy find other matches, but they where refused by the optimizer. The hell if I know why.

    By the way, I'm using v5.6.1 on a Debian woody system.

    Cheers
    Leo TheHobbit
Re: regexp /gs oddity or bug
by belden (Friar) on Apr 22, 2002 at 16:45 UTC
    5.6.1 on alpha is buggy (scalar @a == 1)
    5.6.0 on alpha is ok (scalar @a == 4)

    blyman
    setenv EXINIT 'set noai ts=2'

Re: regexp /gs oddity or bug
by navels (Initiate) on Apr 22, 2002 at 19:17 UTC
    FYI, cygwin's 5.6.1 perl does not have this bug. Lee
Re: regexp /gs oddity or bug
by straywalrus (Friar) on Apr 22, 2002 at 23:39 UTC
    Just another data point: I run perl 5.6.0 on SlakWare 7.1.0 and the output I got from the script,
    $_ = "is this odd or not?"; @a = /(.*? )/gs; print @a;
    was: "is this odd or". nothing was beyond the or

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://161015]
Approved by moodster
Front-paged by RMGir
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2014-07-25 04:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (167 votes), past polls