Course of Raku / Regexes and grammars / Regexes / Quantifiers / Exercises / Two to four

Solution: Two to four

Here is a possible solution to the task.

Code

say 'abcdef' ~~ / \w ** 2..4 /;

🦋 You can find the source code in the file range-quantifier.raku.

Output

「abcd」

Comments

  1. \w ** 2..4 matches from two to four word characters.

  2. Being greedy, it takes as many as the range allows — four — so the match is abcd.

Course navigation

Two to four   |   Captures