Course of Raku / Regexes and grammars / Regexes / Anchors / Start and end of string
Quiz — String anchors
What does the following program print? Note the $ at the
end of the pattern.
say so 'hello world' ~~ / world $/;| 1 | True |
| 0 | False |
| 0 | 「world」 |
| 0 | Nil |
The $ anchor requires the match to finish at the very
end of the string. The string hello world does end with
world, so the anchored pattern succeeds and so
returns True.