E0080#
Warning name: regex_match_missing_before
非流式 lexscan 模式可以跳过输入前缀,但该模式没有绑定或显式忽略这个前缀。
对于 String 和 StringView 输入,未锚定的正则会从输入开头向后搜索。匹配必须从开头开始时,请添加 ^;需要绑定或忽略跳过的前缀时,请添加 before=。
错误示例#
///|
pub fn ends_with_digits(input : String) -> Bool {
lexscan input {
re"[0-9]+$" => true
_ => false
}
}
建议#
将正则锚定在开头,或使用 before=prefix 或 before=_ 显式处理跳过的前缀。
///|
pub fn ends_with_digits(input : String) -> Bool {
lexscan input {
(re"[0-9]+$", before=_) => true
_ => false
}
}