E4220

E4220#

Compiler diagnostic name: regex_match_binding_not_supported.

A lexscan ... with longest case uses a before= binding, which is not available in longest-match mode.

For String and StringView inputs, first-match mode supports both before= and after=. Longest-match mode starts at the beginning of the input, so it supports after= but not before=.

Erroneous example#

///|
pub fn first_word(input : String) -> StringView {
  lexscan input with longest {
    (re"^[a-z]+" as word, before=_) => word
    _ => ""
  }
}

Suggestion#

Remove before=, anchor the regex at ^, and use after= when the unmatched suffix is needed.

///|
pub fn first_word(input : String) -> StringView {
  lexscan input with longest {
    (re"^[a-z]+" as word, after=_) => word
    _ => ""
  }
}