diff --git a/rules/prefer-string-replace-all.js b/rules/prefer-string-replace-all.js index 995db0b70d..5f0e8e032d 100644 --- a/rules/prefer-string-replace-all.js +++ b/rules/prefer-string-replace-all.js @@ -19,7 +19,7 @@ const isRegexWithGlobalFlag = node => function isLiteralCharactersOnly(node) { const searchPattern = node.regex.pattern; - return !/[$()*+.?[\\\]^{}]/.test(searchPattern.replace(/\\[$()*+.?[\\\]^{}]/g, '')); + return !/[$()*+.?[\\\]^{|}]/.test(searchPattern.replace(/\\[$()*+.?[\\\]^{|}]/g, '')); } function removeEscapeCharacters(regexString) { diff --git a/test/prefer-string-replace-all.mjs b/test/prefer-string-replace-all.mjs index 56aabef02c..2bfc78e19d 100644 --- a/test/prefer-string-replace-all.mjs +++ b/test/prefer-string-replace-all.mjs @@ -14,6 +14,7 @@ test({ 'foo.replace(/[a]/g, bar)', 'foo.replace(/a?/g, bar)', 'foo.replace(/.*/g, bar)', + 'foo.replace(/a|b/g, bar)', 'foo.replace(/\\W/g, bar)', 'foo.replace(/\\u{61}/g, bar)', 'foo.replace(/\\u{61}/gu, bar)', @@ -86,6 +87,11 @@ test({ output: 'foo.replaceAll(\'\\\\.\', bar)', errors: [error], }, + { + code: 'foo.replace(/\\|/g, bar)', + output: 'foo.replaceAll(\'|\', bar)', + errors: [error], + }, ], });