Course of Raku / Regexes and grammars / Regexes / Literals and character classes / Exercises / Match a phrase
Solution: Match a phrase
Here is a possible solution to the task.
Code
say 'I love Raku' ~~ / 'love Raku' /;🦋 You can find the source code in the file match-a-word.raku.
Output
「love Raku」Comments
The space between the words is significant here, so the phrase is wrapped in quotes:
'love Raku'. Without the quotes, the regex engine would ignore the space and look forloveRaku, which is not in the string.The smartmatch returns a match object covering the whole quoted phrase, which
sayprints between corner brackets.