# prefer-regex-literals

Prefer regex literals for constant patterns and flags

Constructing a regular expression from constant strings defers a fixed pattern to runtime and doubles string escaping.
Instead, you SHOULD use a regular expression literal when both the pattern and flags are constant.

- Category: style
- Level: warning
- Fix: suggestion
- Scope: module

## Reported

```ds title="main.ds"
const word = new RegExp("\\w+", "u");
```

## Accepted

```ds title="main.ds"
const word = /\w+/u;
```

## Prior art

- [ESLint · prefer-regex-literals](https://eslint.org/docs/latest/rules/prefer-regex-literals)

[language/linter/src/rules/style/prefer_regex_literals.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/prefer_regex_literals.rs#L8)
