Regexes & grammars

Regex adverbs — :i / :s / :g

Full

Modify how a match works — case-insensitive, significant-space, global.

Adverbs tweak a match. Written after the m/s/rx (or on ~~), they turn on case-insensitivity (:i), significant whitespace (:s), global matching (:g), and more.

:i — case-insensitive #

say so "HELLO" ~~ m:i/hello/;
say so "HELLO" ~~ /hello/;
Output
True
False

Without :i, the literal hello doesn't match HELLO.

:s — significant space #

By default whitespace in a regex is ignored. :s (sigspace) makes each space match real whitespace (\s+), so patterns can be laid out with meaningful gaps.

say so "foo   bar" ~~ m:s/foo bar/;
Output
True

:g — global #

:g finds every match, returning a list of them.

say ("a1b2c3" ~~ m:g/\d/).elems;
Output
3

Notes #