use strict;
use warnings;
use feature 'say';
my $run=0;
sub test {
$run++;
my $regex = 'm{}g'; # user input
my $text = 'xx'; # user input
print "--- run $run\n";
pos($text)=0;
eval <<"__CODE__";
say pos(\$text),"<\$&>" while \$text =~ $regex;
__CODE__
}
test();
say "successful /g/" if 'g' =~ /g/;
test();
say "successful /x/" if 'x' =~ /x/;
test();
my $empty='';
say "successful //" if ' ' =~ /$empty/;
test();
####
--- run 1
0<>
1<>
2<>
successful /g/
--- run 2
successful /x/
--- run 3
1
2
--- run 4
1
2
####
...
for my $tybalt (qw/ () | (?:) g{0}/) {
'g' =~ /g/;
say "successful /$tybalt/" if ' ' =~ /$tybalt/;
test();
}
####
successful /()/
--- run 5
0<>
1<>
2<>
successful /|/
--- run 6
0<>
1<>
2<>
successful /(?:)/
--- run 7
0<>
1<>
2<>
successful /g{0}/
--- run 8
0<>
1<>
2<>