E0080

E0080#

Warning name: regex_match_missing_before

A non-streaming lexscan pattern can skip an input prefix, but the pattern does not bind or explicitly ignore that prefix.

For String and StringView inputs, an unanchored regex searches forward from the start of the input. Add ^ when the match must start at the beginning, or add before= to bind or ignore the skipped prefix.

Erroneous example#

///|
pub fn ends_with_digits(input : String) -> Bool {
  lexscan input {
    re"[0-9]+$" => true
    _ => false
  }
}

Suggestion#

Anchor the regex at the start, or make the skipped prefix explicit with before=prefix or before=_.

///|
pub fn ends_with_digits(input : String) -> Bool {
  lexscan input {
    (re"[0-9]+$", before=_) => true
    _ => false
  }
}