Regex literals often contain verbose patterns that can be expressed more concisely using shorthand character classes. This rule usesDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/sindresorhus/eslint-plugin-unicorn/llms.txt
Use this file to discover all available pages before exploring further.
regexp-tree and clean-regexp to detect and rewrite those patterns automatically, keeping your regexes shorter and easier to read.
| Recommended | — |
| Fixable | 🔧 Auto-fix |
| Suggestions | — |
Regexes with the
u or v flag are skipped because regexp-tree does not fully support them.Examples
Configuration
eslint.config.js
sortCharacterClasses
Type: boolean — Default: true
When true, character classes are reordered for consistency (for example, [AaQqTt] becomes [AQTaqt]). Set to false to preserve the original order of characters inside character classes.
eslint.config.js