# E4218

Compiler diagnostic name: `lexscan_pattern_not_anchored`.

A lexical regex pattern is not anchored where anchoring is required.

Patterns used by `lexscan`, including scans of an in-memory
`@lexbuf.StringScanner`, or by `lexmatch` with the `longest` strategy, must
start at the current input position. Anchor each such regex with `^`.

## Erroneous example

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

## Suggestion

Add `^` to the start of the regex. Add `$` as well only when the case must
consume the whole input.

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