in reply to Reset meaning of empty pattern?
They are nice for short scripts but a source of errors in larger apps, because they break orthogonality.
Anyway I'm confused about the result you are expecting... the empty pattern would always match for every position
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<x> 2<x> --- run 4 1<x> 2<x>
so you are looking for a way to reproduce run 1?
I wasn't able to reset the regex engine here
tybalt's suggestions seem to work well:
... 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<>
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
FootballPerl is like chess, only without the dice
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reset meaning of empty pattern?
by haukex (Archbishop) on Sep 01, 2018 at 16:47 UTC | |
by LanX (Saint) on Sep 01, 2018 at 16:57 UTC | |
by haukex (Archbishop) on Sep 01, 2018 at 16:58 UTC |