From 4c6661d0800e446f5d9dfe612ab06f03c0860bd3 Mon Sep 17 00:00:00 2001 From: Axel Delmas Date: Thu, 29 Aug 2019 20:18:00 +0200 Subject: [PATCH] Replace regexEscape function --- src/lib/parse/regex.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lib/parse/regex.js b/src/lib/parse/regex.js index 4b86f34c7d..08457ab368 100644 --- a/src/lib/parse/regex.js +++ b/src/lib/parse/regex.js @@ -49,6 +49,11 @@ function unescapeFormat(s) { })); } +const reRegExpChar = /[\\^$.*+?()[\]{}|]/g; +const reHasRegExpChar = RegExp(reRegExpChar.source); + export function regexEscape(s) { - return s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'); + return (string && reHasRegExpChar.test(string)) + ? string.replace(reRegExpChar, '\\$&') + : string }