26 lines
340 B
JavaScript
26 lines
340 B
JavaScript
|
|
const escapeRegexRegex = new RegExp(
|
||
|
|
"(\\" +
|
||
|
|
[
|
||
|
|
"/",
|
||
|
|
".",
|
||
|
|
"*",
|
||
|
|
"+",
|
||
|
|
"?",
|
||
|
|
"|",
|
||
|
|
"(",
|
||
|
|
")",
|
||
|
|
"[",
|
||
|
|
"]",
|
||
|
|
"{",
|
||
|
|
"}",
|
||
|
|
"\\",
|
||
|
|
"$",
|
||
|
|
"^"
|
||
|
|
].join("|\\") +
|
||
|
|
")",
|
||
|
|
"gim"
|
||
|
|
);
|
||
|
|
export default function (str) {
|
||
|
|
return str.replace(escapeRegexRegex, "\\$1");
|
||
|
|
}
|