Course of Raku / Regexes and grammars / Regexes / Substitution and replacement / Exercises / Mask the digits
Solution: Mask the digits
Here is a possible solution to the task.
Code
my $orig = 'PIN 1234';
say S:g/\d/#/ given $orig;
say $orig;🦋 You can find the source code in the file mask-digits.raku.
Output
PIN ####
PIN 1234Comments
The uppercase
S///does the same job ass///but returns a new string instead of changing the variable in place. With:git replaces every digit\dwith a#in the returned copy. It is applied to$origwithgiven, which sets the string as the topic.Printing
$origafterwards shows it still holdsPIN 1234— unlikes///, the original was left untouched.
Course navigation
← Mask the digits | Grammars →