E4181#
Compiler diagnostic name: named_capture_in_regex_literal_used_in_lex_is_not_supported.
lexmatch 使用的正则字面量不支持命名捕获组。
lexmatch 可以通过词法模式中的位置绑定器绑定正则模式的部分内容。正则本身内部的命名捕获组不属于受支持的词法模式绑定模型,因此会被拒绝。
错误示例#
///|
pub fn match_text(text : String) -> Unit {
lexmatch text with longest {
("(?<word>abc)", _) => ()
_ => ()
}
}
该正则包含命名捕获组 (?<word>...)。
修改建议#
使用普通正则分组;需要时,通过外层词法模式绑定匹配到的剩余部分。
///|
pub fn match_text(text : String) -> Unit {
lexmatch text with longest {
("abc", _) => ()
_ => ()
}
}