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+15

Comments

  1. \d+ matches a whole run of digits, and :g collects every such run — here 5, 10, and 15.

  2. Each match is a match object, so .map(*.Str) turns them into plain strings before joining them with +.

Course navigation

All the numbers   |   Substitution and replacement