E4183#
Compiler diagnostic name: regex_interpolation_is_not_supported.
Regex interpolation is not supported in lexmatch patterns.
lexmatch patterns are compiled as part of the match. They must be known as
literal regex patterns instead of being built with string or regex
interpolation.
Erroneous example#
///|
pub fn match_text(text : String, part : String) -> Unit {
lexmatch text with longest {
("\{part}", _) => ()
_ => ()
}
}
The regex pattern tries to interpolate part.
Suggestion#
Use a literal pattern in the lexmatch case. For dynamic regex matching, build a
regex value and use a regex match expression instead of lexmatch.
///|
pub fn match_text(text : String) -> Unit {
lexmatch text with longest {
("abc", _) => ()
_ => ()
}
}