Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: Seeking clarification on possible bug in regex using \G and /gc

by Rhandom (Curate)
on Mar 14, 2018 at 23:24 UTC ( [id://1210924]=note: print w/replies, xml ) Need Help??


in reply to Re: Seeking clarification on possible bug in regex using \G and /gc
in thread Seeking clarification on possible bug in regex using \G and /gc

Breaks for me on perl 5.26.
perl -E 'local $_ = "foo"; say "Start" if /\G foo/gcx; say "Mid" if /\ +G .*/gcx; say "End" if /\G \z/gcx' Start Mid
Should instead print
Start Mid End
Here is a more extended item looking at pos as well.
perl -E 'local $_ = "foo"; say "Start" if /\G foo/gcx; say pos; say "M +id" if /\G .*/gcx; say pos; say "End" if /\G \z/gcx; say "At End" if +pos == length' Start 3 Mid 3 At End
my @a=qw(random brilliant braindead); print $a[rand(@a)];

Replies are listed 'Best First'.
Re^3: Seeking clarification on possible bug in regex using \G and /gc
by choroba (Cardinal) on Mar 14, 2018 at 23:52 UTC
    > Should instead print

    Why? Using perl -Mre=debug will show you your mistake:

    ... Matching REx "\G \z" against "" 3 <foo> <> | 1:GPOS(2) 3 <foo> <> | 2:EOS(3) 3 <foo> <> | 3:END(0) Match possible, but length=0 is smaller than requested=1, failing! Match failed

    The length=1 request comes from the previously mentioned Repeated Patterns Matching a Zero-length Substring:

    The higher-level loops preserve an additional state between iterations: whether the last match was zero-length. To break the loop, the following match after a zero-length match is prohibited to have a length of zero.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2024-03-28 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found