| 标题 | 标签 |
|---|---|
| cloneRegExp(正则表达式的复制) | type,intermediate(类型,两者之间的) |
复制一个正则表达式。
- 使用
new RegExp()、RegExp.prototype.source和RegExp.prototype.flags复制给定的正则表达式。
代码如下:
const cloneRegExp = regExp => new RegExp(regExp.source, regExp.flags);ts 代码如下:
调用方式:
const regExp = /lorem ipsum/gi;
const regExp2 = cloneRegExp(regExp); // regExp !== regExp2应用场景
以下是一个实战示例:
结果如下:
<iframe src="codes/javascript/html/clone-reg-exp.html"></iframe>