Is is possible escape parameterized regex when parameter contains multiple simbols that need to be escaped?
const _and = \'&&\', _or = \'||\';
let re
EDITED https://jsfiddle.net/ao4t0pzr/1/
You can use a Template Literal function to escape the characters within the string using a Regular Expression. You can then use that string to propagate a new RegEx filled with escaped characters:
function escape(s) {
return s[0].replace(/[-&\/\\^$*+?.()|[\]{}]/g, '\\$&');
};
var or = escape`||`;
var and = escape`&&`;
console.log(new RegExp(`${and}|${or}`)); // "/\&\&|\|\|/"