Course of Raku / Regexes and grammars / Regexes / Adverbs / Exercises / All the numbers
Solution: All the numbers
Here is a possible solution to the task.
Code
my @numbers = 'x=5, y=10, z=15' ~~ m:g/\d+/;
say @numbers.map(*.Str).join('+');🦋 You can find the source code in the file all-numbers.raku.
Output
5+10+15Comments
\d+matches a whole run of digits, and:gcollects every such run — here5,10, and15.Each match is a match object, so
.map(*.Str)turns them into plain strings before joining them with+.