develooper Front page | perl.perl5.porters | Postings from July 2013

[perl #114884] perl -le '$_="abcdefg123456"; s/(?<=...\G)?(\d)/($1)/; print'

Thread Next
From:
Father Chrysostomos via RT
Date:
July 25, 2013 05:55
Subject:
[perl #114884] perl -le '$_="abcdefg123456"; s/(?<=...\G)?(\d)/($1)/; print'
Message ID:
rt-3.6.HEAD-2552-1374731731-60.114884-15-0@perl.org
On Sat Jun 22 11:01:38 2013, davem wrote:
> I've just got onto the \G mess, and to avoid clashes, I've cherry-picked
> your smoke commit into my private branch. So, if it's ok with you, could
> you skip pushing it to blead, as it will get there when my branch gets
> merged anyway?

Speaking of the \G mess, I’ve been reviewing your work, and it occurs to
me that it doesn’t make sense for /.\G/ to match at all.

I would expect that after

pos($_) = 5;
/$anything/g;

$-[0] would be >= 5 as long as the match succeeded.

Allowing the regexp engine to start *before* the current starting
position breaks that basic assumption.

Guess what this does:

$_ = "\n,rekcah lreP rehtona tsuJ ";
pos = length;
while(/aa\G|.(?=.\G)/gs) { print $& }

(Your branch actually breaks that.)

That I have to use aa\G at the beginning to trick perl into starting two
characters before pos suggests that this can never really work
logically.  If I change that to aa(?!b)b?\G, which is logically the same
thing, the regexp engine no longer starts before pos().

Now the subject of this ticket is /(?<=aaa\G)?bbb/, which actually
*does* make sense, unlike the /.\G/ weirdness, since it is equivalent to
/(?:\G(?<=aaa))?bbb/, which has \G at the beginning.

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=114884

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About