# E4220

Compiler diagnostic name: `regex_match_binding_not_supported`.

A lexical case uses a binding that is not available in its matching mode.

For `String` and `StringView` inputs, first-match `lexmatch` supports both
`before=` and `after=`. Longest-match mode starts at the beginning of the input,
so it supports `after=` but not `before=`. `lexscan` does not support either
binding: streaming targets consume their input buffers, while an in-memory
`@lexbuf.StringScanner` stores the next scan position in its `cursor` field.

## Erroneous example

```{literalinclude} /sources/error_codes/4220_error/top.mbt
:language: moonbit
```

## Suggestion

For `lexscan`, remove `before=` or `after=` and anchor the regex at `^`. For
`lexmatch`, remove `before=`, anchor the regex at `^`, and use `after=` when the
unmatched suffix is needed.

```{literalinclude} /sources/error_codes/4220_fixed/top.mbt
:language: moonbit
```
