E4183

E4183#

Compiler diagnostic name: regex_interpolation_is_not_supported.

此诊断描述的是早期词法模式形式中的插值,当前编译器不会发出该诊断。

当前的 lexmatchlexscan 分支使用正则常量表达式。运行时字符串插值不是正则分支模式。

错误示例#

///|
pub fn match_text(text : String, part : String) -> Unit {
  lexmatch text with longest {
    ("\{part}", _) => ()
    _ => ()
  }
}

该正则模式尝试插入 part

修改建议#

请使用正则字面量或具名正则常量。动态匹配请使用常规 Regex API。

///|
pub fn match_text(text : String) -> Unit {
  lexmatch text with longest {
    (re"^abc", after=_) => ()
    _ => ()
  }
}