Course of Raku / Regexes and grammars / Regexes / Adverbs
Case-insensitive matching
Normally a regex distinguishes upper-case from lower-case letters:
/hello/ does not match HELLO. The
:i adverb (short for :ignorecase) turns that
distinction off:
say 'HELLO' ~~ /:i hello/; # 「HELLO」With :i, the letters match regardless of case, so the
lower-case pattern matches the upper-case text. It works in either
direction and for mixed case too:
say 'I use RAKU' ~~ /:i raku/; # 「RAKU」You can also write the adverb on the m/// operator
instead of inside the pattern:
say 'HELLO' ~~ m:i/hello/; # 「HELLO」Both of these make the whole pattern ignore case. The next page looks more closely at where an adverb applies — the difference between the two placements — and how to switch case-sensitivity back on for part of a pattern.
Practice
Complete the quiz that covers the contents of this topic.
Course navigation
← Adverbs | Quiz — Ignorecase →
💪 Or jump directly to
the exercises in this section.