Pular para o conteúdo

useRegexpExec

Este conteúdo não está disponível em sua língua ainda.

biome.json
{
"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.

invalid.ts
'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.

valid.ts
/thing/.exec('something');