diff --git a/src/core/Cool-str.pm b/src/core/Cool-str.pm index 99f6521d03b..6aad21ae4eb 100644 --- a/src/core/Cool-str.pm +++ b/src/core/Cool-str.pm @@ -177,24 +177,27 @@ augment class Cool { self gt '' ?? self.substr(0,1).lc ~ self.substr(1) !! "" } - our multi method match(Regex $pat, :c(:$continue), :g(:$global)) { + our multi method match(Regex $pat, :c(:$continue), :g(:$global), :pos(:$p)) { if $continue ~~ Bool { note ":c / :continue requires a position in the string"; fail ":c / :continue requires a position in the string"; } + my %opts; + %opts

= $p if defined $p; + %opts = $continue // 0 unless defined $p; + if $global { - my $cont = $continue; - gather while my $m = Regex::Cursor.parse(self, :rule($pat), :c($cont)) { + gather while my $m = Regex::Cursor.parse(self, :rule($pat), |%opts) { my $m-copy = $m; take $m-copy; if $m.to == $m.from { - $cont = $m.to + 1; + %opts = $m.to + 1; } else { - $cont = $m.to; + %opts = $m.to; } } } else { - Regex::Cursor.parse(self, :rule($pat), :c($continue)); + Regex::Cursor.parse(self, :rule($pat), |%opts); } } diff --git a/t/spectest.data b/t/spectest.data index 21843f3666d..911b621b056 100644 --- a/t/spectest.data +++ b/t/spectest.data @@ -284,6 +284,7 @@ S05-modifier/global.t # S05-modifier/perl5_2.t # S05-modifier/perl5_7.t # S05-modifier/perl5_8.t +S05-modifier/pos.t S05-substitution/match.t S05-substitution/subst.t # S05-transliteration/trans.t