Course of Raku / Regexes and grammars / Regexes / Lookaround assertions / Lookahead
Quiz — Lookahead
What does the following program print?
say '5 cm' ~~ / \d+ <?before ' cm'> /;| 1 | 「5」 |
| 0 | 「5 cm」 |
| 0 | False |
| 0 | Nil |
The positive lookahead <?before ' cm'> requires
the digits to be followed by cm, which they are. The
assertion checks that text but does not consume it, so the match is just
the digits, 「5」.
Course navigation
← Lookahead | Lookbehind →