> On Aug 27, 2022, at 10:56 AM, Marc Chantreux <m...@unistra.fr> wrote:
--snip--
> but I think it is possible to move the cursor backward in the comb regex.
--snip--
I do *not* think you can ("move the cursor backward in the comb regex"); See
https://docs.raku.org/routine/comb :
... "returns a Seq of non-overlapping matches" ...
The "non-overlapping" nature is the problem.
(Please let me know if this turns out to be incorrect!)
In foresight, Raku has added an optional `:exhaustive` flag to regex matching,
and that will do what you want.
This Raku code:
my %digraphs = slurp.lc.match(:exhaustive, /(<[a..z]> ** 2)/)ยป.Str.Bag;
.say for %digraphs.sort({ -.value, ~.key });
, produces output identical to this Perl code:
perl -lnE '
END { say "$_ => $digraph{$_}" for
sort { $digraph{$b} <=> $digraph{$a} || $a cmp $b }
keys %digraph
}
$_=lc; while (/([a-z]{2})/g) {++$digraph{$1}; --pos; }
' Camelia.svg
, when run against a downloaded copy of our mascot:
https://upload.wikimedia.org/wikipedia/commons/8/85/Camelia.svg
--
Hope this helps,
Bruce Gray (Util of PerlMonks)