src/content/docs/linter/rules/use-regexp-exec.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: :::note This rule belongs to the types domain. This means that its activation will activate the Biome Scanner to scan the files of your project, and enable the type inference engine. Read more about it in the [documentation page](/linter/domains#types) ::: ## Summary - Rule available since: `v2.3.9` - Diagnostic Category: [`lint/nursery/useRegexpExec`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - This rule belongs to the following domains: - [`types`](/linter/domains#types) - Sources: - Same as [`@typescript-eslint/prefer-regexp-exec`](https://typescript-eslint.io/rules/prefer-regexp-exec) - Same as [`regexp/prefer-regexp-exec`](https://ota-meshi.github.io/eslint-plugin-regexp/rules/prefer-regexp-exec.html){
"linter": {
"rules": {
"nursery": {
"useRegexpExec": "error"
}
}
}
}
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.
'something'.match(/thing/);
/thing/.exec('something');