RegExp.prototype.compile()
Deprecated
已废弃的 compile() 方法被用于在脚本执行过程中(重新)编译正则表达式。与 RegExp 构造函数基本一样。
语法
regexObj.compile(pattern, flags)
参数
描述
不推荐 compile 方法。你可以使用 RegExp 构造函数来得到相同效果。
示例
>使用 compile()
以下展示如何用新模式和新标志来重新编译正则表达式。
js
var regexObj = new RegExp("foo", "gi");
regexObj.compile("new foo", "g");
规范
| 规范 |
|---|
| ECMAScript® 2027 Language Specification> # sec-regexp.prototype.compile> |