develooper Front page | perl.perl5.porters | Postings from September 2012

[perl #114804] correction to documentation

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
September 16, 2012 19:27
Subject:
[perl #114804] correction to documentation
Message ID:
rt-3.6.HEAD-11172-1347848820-1651.114804-15-0@perl.org
On Sun Sep 09 03:12:14 2012, pure.mathmo@googlemail.com wrote:
> Hi,
> 
> I'm not sure if I'm reporting this the right way. It's not a bug exactly,
> in the sense I think it's the documentation that needs to be changed to
> match the code, not vice versa.
> 
> At http://perldoc.perl.org/perlre.html#Combining-RE-Pieces , it says that
> the regex S{min,max} is equivalent to S{max}|...|S{min}. But consider the
> following code:
>     'abc' =~ /(abc|a|b){1,2}/;
>     print $& . "\n";        # prints 'abc'
>     'abc' =~ /(abc|a|b){2}|(abc|a|b){1}/;
>     print $& . "\n";        # prints 'ab'
> The lazy match is also wrong:
>     'abcc' =~ /(a|b|abc){1,2}?c/;
>     print $& . "\n";        # prints 'abc'
>     'abcc' =~ /((a|b|abc){1}|(a|b|abc){2})c/;
>     print $& . "\n";        # prints 'abcc'
> 
> I think what you meant to say was that it's a lexicographic ordering. More
> formally:
>   - S{min,max} == S{min}S{0,max-min}
>   - S{0,n+1} == (?:SS{0,n})?
>   - S{0} == (?:)
> and similarly, for lazy match:
>   - S{min,max}? == S{min}S{0,max-min}?
>   - S{0,n+1}? == (?:SS{0,n}?)??
>   - S{0}? == (?:)
> 
> I think the nub of the gotcha is that concatenation of regexes is not
> left-distributive over | , i.e.:
>     S{1,2} == S(S|) != SS|S
> and right-distributivity is true but irrelevant:
>     S{1,2} != (S|)S == SS|S
> 

Could someone with regex expertise confirm whether this report of a
documentation error is correct?

Thank you very much.
Jim Keenan


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

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