unicorn/prefer-regexp-exec
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-regexp-exec": "error",
},
},
];Prefer RegExp#exec() over String#match() for non-global regular expressions.
const match = text.match(/uni(corn)/);const match = text.match(pattern);const match = /uni(corn)/.exec(text);const match = pattern.exec(text);Examples from the ESLint documentation.
unicorn/prefer-regexp-exec
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-regexp-exec": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
"RegExp.exec()" should be preferred over "String.match()"
Enforce RegExp#exec over String#match if no global flag is provided
Prefer Promise.try() over promise-wrapping boilerplate.
Prefer :scope when using element query selector methods.
Prefer private class fields over the underscore-prefix convention.