Clones a regular expression.

Use new RegExp(), RegExp.source and RegExp.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); // /lorem ipsum/gi