new RegExp(), RegExp.prototype.source and RegExp.prototype.flags to clone the given regular expression.const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);
const regExp = /lorem ipsum/gi; const regExp2 = cloneRegExp(regExp); // regExp !== regExp2
Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️