# E4185

Compiler diagnostic name: `invalid_lex_pattern`.

Invalid `lexmatch` pattern shape.

`lexmatch` patterns allow one regex pattern, optionally with a start rest binder
and an end rest binder. Other top-level pattern shapes are invalid.

```{warning}
`lexmatch` is deprecated for new code. Prefer regex match expressions such as
`value =~ (re"...", before~, after~)` unless you specifically need legacy
lexer-style behavior.
```

## Erroneous example

The following pattern has too many top-level pieces:

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

MoonBit will report an error.

## Suggestion

Use one regex pattern plus optional start and end rest binders. In new code, a
regex match expression is usually clearer:

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