develooper Front page | perl.perl5.porters | Postings from March 2019

[perl #133940] bug of regex?

Thread Previous
From:
James E Keenan via RT
Date:
March 20, 2019 13:14
Subject:
[perl #133940] bug of regex?
Message ID:
rt-4.0.24-27401-1553087674-828.133940-15-0@perl.org
On Mon, 18 Mar 2019 01:19:11 GMT, malincns@163.com wrote:
> This is a bug report for perl from malincns@163.com,
> generated with the help of perlbug 1.41 running under perl 5.28.1.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> This report is about capture group.
> I'm not sure whether it's a bug of Perl, or an intended policy.
> 
> string : "abab"
> pattern: /(?:[^b]*(?=(b)|(a))ab)*/
> 
> print defined($1)?"\"$1\"":"undef",", ",defined($2)?"\"$2\"":"undef",
> if
> "abab" =~ /(?:[^b]*(?=(b)|(a))ab)*/;
> 
> Output:
> "b", "a"
> 
> Excepted output:
> undef, "a"
> 
> Some engines output:
> 
> Perl 5.28.1      "b", "a"
> PHP 7.3.2      NULL, "a"
> Java 11.0.2      "b", "a" [1]
> Ruby 2.6.1      nil, "a"
> Go 1.12       [2]
> Rust 1.32.0      [2]
> Node.js 10.15.1   undef, "a"
> Python 3.7.2      "b", "a" [3]
> 
> [1] seems this bug:
> https://bugs.java.com/bugdatabase/view_bug.do?bug_id=7145888
> [2] doesn't support lookaround.
> [3] it's a bug: https://bugs.python.org/issue35859
> 
> 
> Another doubtful case:
> 
> string : "ab"
> pattern: /.*?(?=(a)|(b))b$/
> 
> print defined($1)?"\"$1\"":"undef",", ",defined($2)?"\"$2\"":"undef",
> if
> "ab" =~ /.*?(?=(a)|(b))b$/;
> 
> Output:
> "a", "b"
> 
> Except output:
> undef, "b"
> 

In each of these two cases, can you explain -- in your own words, and without reference to any other language's regex engines -- why you have come to the expectations you have?

Thank you very much.

-- 
James E Keenan (jkeenan@cpan.org)

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

Thread Previous


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