NERDVANA has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I ran across a strange behavior and I'm wondering if it is a bug, or some obscure documented behavior I should keep in mind.
These match:
# (not using 'say' because I wanted to try it on old perl versions) perl -e 'printf "%s\n", "ab\nab\n" =~ /^ab$ab$/m' perl -e 'printf "%s\n", "ab\nab\n" =~ /^(ab$ab$)/m' perl -e 'printf "%s\n", "ab\nab\n" =~ /^(ab$ab)$/m' perl -e 'printf "%s\n", "ab\nab\n" =~ /^(ab)$ab$/m' perl -e 'printf "%s\n", "ab\nab\n" =~ /^(a)b$ab$/m'
(with '$' consuming a "\n" because it is /m mode)
These do not match:
perl -e 'printf "%s\n", "ab\nab\n" =~ /^(ab$a)b$/m' perl -e 'printf "%s\n", "ab\nab\n" =~ /^(ab$)ab$/m' perl -e 'printf "%s\n", "ab\nab\n" =~ /^ab$(ab)$/m' perl -e 'printf "%s\n", "ab\nab\n" =~ /^(ab$){2}/m' perl -e 'printf "%s\n", "ab\nab\n" =~ /(ab$){2}/m' perl -e 'printf "%s\n", "ab\nab\n" =~ /(?^:^(?^m:(ab$){2}))/m'
This is greedy but only matches one line
perl -e 'printf "%s\n", "ab\nab\n" =~ /^((?:ab$)+)/m'
and it seems to me that all of them should match. This appears to happen as old as 5.8.9 and as new as 5.32.1
Any insights?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regex bug? matching multiple newline with /m
by tybalt89 (Monsignor) on Aug 09, 2021 at 08:31 UTC | |
by NERDVANA (Deacon) on Aug 09, 2021 at 10:41 UTC | |
by AnomalousMonk (Archbishop) on Aug 09, 2021 at 14:51 UTC | |
by BillKSmith (Monsignor) on Aug 14, 2021 at 15:23 UTC | |
Re: Regex bug? matching multiple newline with /m
by haukex (Archbishop) on Aug 09, 2021 at 18:58 UTC | |
Re: Regex bug? matching multiple newline with /m (rxrxplainer)
by Anonymous Monk on Aug 09, 2021 at 09:07 UTC |
Back to
Seekers of Perl Wisdom