useRegexpExec
Цей контент ще не доступний вашою мовою.
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/useRegexpExec - This rule doesn’t have a fix.
- The default severity of this rule is information.
- This rule belongs to the following domains:
- Sources:
- Same as
@typescript-eslint/prefer-regexp-exec - Same as
regexp/prefer-regexp-exec
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useRegexpExec": "error" } } }}Description
Section titled “Description”Enforce RegExp#exec over String#match if no global flag is provided.
String#match is defined to work the same as RegExp#exec when the regular expression does not include the g flag. Keeping to consistently using one of the two can help improve code readability.
RegExp#exec may also be slightly faster than String#match; this is the reason to choose it as the preferred usage.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”'something'.match(/thing/);/invalid.ts:1:1 lint/nursery/useRegexpExec ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Prefer RegExp#exec() over String#match() when searching within a string.
> 1 │ ‘something’.match(/thing/);
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Use RegExp#exec() instead of String#match() for consistent and slightly faster regex matching.
/thing/.exec('something');Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.