8000 docs: `require-unicode-regexp` add note for `i` flag and `\w` (#19510) · eslint/eslint@fe92927 · GitHub
[go: up one dir, main page]

Skip to content

Commit fe92927

Browse files
docs: require-unicode-regexp add note for i flag and \w (#19510)
* Update require-unicode-regexp.md * Update require-unicode-regexp.md * Update require-unicode-regexp.md * Update docs/src/rules/require-unicode-regexp.md Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com> --------- Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
1 parent f4e9c5f commit fe92927

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/src/rules/require-unicode-regexp.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,27 @@ const fooRegexp = new RegExp('foo', 'v');
182182
## When Not To Use It
183183
184184
If you don't want to warn on regular expressions without either a `u` or a `v` flag, then it's safe to disable this rule.
185+
186+
### Note on `i` flag and `\w`
187+
188+
In some cases, adding the `u` flag to a regular expression using both the `i` flag and the `\w` character class can change its behavior due to Unicode case folding.
189+
190+
For example:
191+
192+
```js
193+
const regexWithoutU = /^\w+$/i;
194+
const regexWithU = /^\w+$/iu;
195+
196+
const str = "\u017f\u212a"; // Example Unicode characters
197+
198+
console.log(regexWithoutU.test(str)); // false
199+
console.log(regexWithU.test(str)); // true
200+
```
201+
202+
If you prefer to use a non-Unicode-aware regex in this specific case, you can disable this rule using an `eslint-disable` comment:
203+
204+
```js
205+
/* eslint-disable require-unicode-regexp */
206+
const regex = /^\w+$/i;
207+
/* eslint-enable require-unicode-regexp */
208+
```

0 commit comments

Comments
 (0)
0