# E4210

Compiler diagnostic name: `regex_alias_in_alternation`.

Regex alias is not allowed inside an alternation branch.

In a regex match expression, `as` binds the matched text. When the pattern uses
alternation with `|`, bind the whole alternation instead of binding only one
branch. Otherwise the binder would exist only for some alternatives.

## Erroneous example

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

`left` is bound only when the first branch matches.

## Suggestion

Move the alias outside the alternation so it is defined no matter which branch
matches.

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