Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Precise backreference semantics in Perl regular expressions

by tybalt89 (Monsignor)
on Nov 10, 2023 at 04:13 UTC ( [id://11155536]=note: print w/replies, xml ) Need Help??


in reply to Re: Precise backreference semantics in Perl regular expressions
in thread Precise backreference semantics in Perl regular expressions

Opinion...

#!/usr/bin/perl use strict; #use warnings; for my $regexp ( qr/^((a*)b|a*b?d)*c\2$/, qr/^(a*b?d|(a*)b)*c\2$/, qr/^((a*)b|a*b?d())*c\2$/, # NOTE these two fixed to work the way qr/^(?|a*b?d()|(a*)b)*c\1$/, # I think they should work ) { for my $string (qw( aabadcaa aababdcaa )) { print "\n$string\n$regexp\n"; print $string =~ /$regexp/ ? 'Yes' : 'No', "\n"; } } print <<END; This is perl 5, version 38, subversion 0 (v5.38.0) built for x86_64-li +nux-thread-multi END

Outputs:

aabadcaa (?^:^((a*)b|a*b?d)*c\2$) No aababdcaa (?^:^((a*)b|a*b?d)*c\2$) No aabadcaa (?^:^(a*b?d|(a*)b)*c\2$) Yes aababdcaa (?^:^(a*b?d|(a*)b)*c\2$) Yes aabadcaa (?^:^((a*)b|a*b?d())*c\2$) No aababdcaa (?^:^((a*)b|a*b?d())*c\2$) No aabadcaa (?^:^(?|a*b?d()|(a*)b)*c\1$) No aababdcaa (?^:^(?|a*b?d()|(a*)b)*c\1$) No This is perl 5, version 38, subversion 0 (v5.38.0) built for x86_64-li +nux-thread-multi

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11155536]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-05-27 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found