# E4182

Compiler diagnostic name: `regex_constant_ref_in_lex_is_not_supported`.

Regex constants are not supported in this `lexmatch` context.

Legacy `lexmatch` can use regex constants only in limited contexts: a
`StringView` target with the default first-match strategy. Other `lexmatch`
forms, such as `with longest`, require literal regex patterns.

```{warning}
`lexmatch` is deprecated for new code. Prefer regex match expressions such as
`value =~ SOME_REGEX` unless you specifically need legacy lexer-style behavior.
```

## Erroneous example

The following example uses a regex constant in a longest-match `lexmatch`:

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

MoonBit will report an error.

## Suggestion

Use a literal regex pattern in that `lexmatch` case, or rewrite the code with a
regex match expression:

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