# E4171

Compiler diagnostic name: `last_regex_case_must_be_catchall`.

The last case in a `lexmatch` expression must be a catch-all pattern.

MoonBit checks `lexmatch` expressions for exhaustiveness. When all previous
regex patterns fail, the expression still needs a final branch that can handle
the remaining input.

## Erroneous example

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

The only branch matches `"abc"`, so other input has no branch to run.

## Suggestion

Add a final `_` case, or otherwise make the last case catch all remaining input.

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