💼 This rule is enabled in the ✅ recommended
config.
🔧 This rule is automatically fixable by the --fix
CLI option.
The String#replaceAll()
method is both faster and safer as you don't have to use a regex and remember to escape it if the string is not a literal. And when used with a regex, it makes the intent clearer.
string.replace(/RegExp with global flag/igu, '');
string.replace(/RegExp without special symbols/g, '');
string.replace(/\(It also checks for escaped regex symbols\)/g, '');
string.replace(/Works for u flag too/gu, '');
string.replaceAll(/foo/g, 'bar');
string.replace(/Non-global regexp/iu, '');
string.replace('Not a regex expression', '')
string.replaceAll('string', '');
string.replaceAll(/\s/g, '');
string.replaceAll('foo', 'bar');