With my version of Rakudo (v2022.07
), the following escape-wrapping works:
- take the literal and wrap in
q[
…]
,
- take the
q[…]
above and wrap in <{
…}>
.
Tested as a one-liner at either the zsh
or bash
command line:
~$ zsh
~% raku -e 'say "food" ~~ / . <{ q[oo] }> /;'
「foo」
~% bash
~$ raku -e 'say "food" ~~ / . <{ q[oo] }> /;'
「foo」
Variations of Raku's "Q-language" can be tried: I've had success with square brackets as above. See: https://docs.raku.org/language/quoting.html . Note, make sure you add the <
>
angle brackets, otherwise the literal wrapped in {
}
curlies will appear invisible (it gets executed as a codeblock):
~$ zsh
~% raku -e 'say "food" ~~ / { q[food] } /;'
「」
~% raku -e 'say "nothing" ~~ / { q[nothing] } /;'
「」
~% bash
~$ raku -e 'say "food" ~~ / { q[food] } /;'
「」
~$ raku -e 'say "nothing" ~~ / { q[nothing] } /;'
「」
Above might be most useful for cross-platform Regexes, rather that swapping Linux/Unix "external-single-and-internal-double-quotes" for Windows "external-double-and-internal-single-quotes", and vice-versa. You can even try using qb[…]
to get backslash-escape recognition (e.g. useful for problematic \n
newline recognition):
~$ zsh
~% raku -e 'say "food\ntruck" ~~ / . <{qb[ ood \\n tru ]}> .. /;'
「food
truck」
~% bash
~$ raku -e 'say "food\ntruck" ~~ / . <{qb[ ood \\n tru ]}> .. /;'
「food
truck」
Credit to @fecundf for starting many of us on the topic of understanding/codifying interpolation within a regex matcher (feel free to peruse the thread below).
https://www.nntp.perl.org/group/perl.perl6.users/2019/09/msg6960.html