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

Re: [perl #116537] Regex: (*THEN) doesn't work as described

Thread Previous | Thread Next
From:
Ronald J Kimball
Date:
January 25, 2013 22:17
Subject:
Re: [perl #116537] Regex: (*THEN) doesn't work as described
Message ID:
20130125221703.GB3898@penkwe.pair.com
On Fri, Jan 25, 2013 at 09:23:54AM -0800, Philip Hazel wrote:

> My understanding of how (*THEN) works is that the test below should 
> match. The perlre page says "...this verb always matches, and when
> backtracked into on failure, it causes the regex engine to try the next
> alternation in the innermost enclosing group (capturing or otherwise)
> that has alternations." Unless I am going mad, the examples below (one a 
> normal group, the other an assertion) fulfil the condition.
> 
> $ perl -e 'print (("ac" =~ /^(?=ab|ac)/)? "yes\n":"no\n")'
> yes
> $ perl -e 'print (("ac" =~ /^(?=a(*THEN)b|ac)/)? "yes\n":"no\n")'
> no
> 
> $ perl -e 'print (("ac" =~ /^(ab|ac)/)? "yes\n":"no\n")'
> yes
> $ perl -e 'print (("ac" =~ /^(a(*THEN)b|ac)/)? "yes\n":"no\n")'
> no

These work in 5.10.1, but not in 5.14.1.

These are the only tests involving (*THEN) that expect a successful match,
from t/re/pat_advanced.t:

    {
        #Mindnumbingly simple test of (*THEN)
        for ("ABC","BAX") {
            ok /A (*THEN) X | B (*THEN) C/x, "Simple (*THEN) test";
        }
    }

The key difference seems to be that in your tests, the two alternations
begin with the same character.

Ronald

Thread Previous | 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