Elegant way to find repeated digits in Raku (née Perl 6)

'12334555611'.comb(/\d+ % <same>/)

Please check the answer of the first task of Perl Weekly Challenge


You may use

$n.comb(/(.) $0*/)

The (.) creates a capturing group and captures any char into Group 1, then there is a backreference to Group 1 that is $0 in Perl6 regex. The * quantifier matches zero or more occurrences of the same char as in Group 1.

Replace the . with \d to match any digit if you need to only match repeated digits.

See a Perl6 demo online.

Tags:

Regex

Raku