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
The
?after.+makes the quantifier frugal, so it matches as few characters as possible.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 →