Course of Raku / Regexes and grammars / Regexes / Quantifiers / Exercises / A frugal match

Solution: A frugal match

Here is a possible solution to the task.

Code

say 'say "hi" and "bye"' ~~ / '"' .+? '"' /;

🦋 You can find the source code in the file frugal-match.raku.

Output

「"hi"」

Comments

  1. The ? after .+ makes the quantifier frugal, so it matches as few characters as possible.

  2. It therefore stops at the first closing ", capturing just "hi". A greedy .+ would have run all the way to the last " and matched "hi" and "bye".

Course navigation

A frugal match   |   Two to four