E4181#
Compiler diagnostic name: named_capture_in_regex_literal_used_in_lex_is_not_supported.
Named capture groups are not supported in regex literals used by lexmatch or
lexscan.
lexmatch and lexscan bind matched text with MoonBit's as syntax. Named
capture groups inside the regex itself are not part of this binding model.
Erroneous example#
///|
pub fn match_text(text : String) -> Unit {
lexmatch text with longest {
re"^(?<word>abc)$" => ()
_ => ()
}
}
The regex contains the named capture group (?<word>...).
Suggestion#
Use a normal regex group and bind the matched text with as.
///|
pub fn match_text(text : String) -> Unit {
lexmatch text with longest {
(re"^(abc)$" as word) => ignore(word)
_ => ()
}
}