In Regexes§

See primary documentation in context for Regex interpolation.

Instead of using a literal pattern for a regex match, you can use a variable that holds that pattern. This variable can then be 'interpolated' into a regex, such that its appearance in the regex is replaced with the pattern that it holds. You can also use a block of code, the return value of which may be used literally, interpreted as a regex, or interpreted as a Boolean that either allows the match or prevents it.

The advantage of using interpolation this way, is that the pattern need not be hardcoded in the source of your Raku program, but may instead be variable and generated at runtime.

There are five different ways of interpolating a variable or code-block into a regex as a pattern, which may be summarized as follows:

SyntaxDescription
$variable, @variableInterpolates stringified contents of variable literally.
$(code), @(code)Runs Raku code inside the regex, and interpolates the stringified return value literally.
<$variable> <@variable>Interpolates stringified contents of variable as a regex.
<{code}>Runs Raku code inside the regex, and interpolates the stringified return value as a regex.
<?{code}>, <!{code}>Evaluates Raku code inside the regex in Boolean context, with result either allowing or preventing the match.

The use of hashes in regexes is reserved.