已废弃
该特性已经从 Web 标准中删除,虽然一些浏览器目前仍然支持它,但也许会在未来的某个时间停止支持,请尽量不要使用该特性。
已废弃的compile
()
方法被用于在脚本执行过程中(重新)编译正则表达式。与RegExp
构造函数基本一样。
regexObj.compile(pattern, flags)
pattern
flags
如果指定,标志可以具有以下值的任意组合:
g
i
m
y
不推荐compile方法。你可以使用
RegExp
构造函数来得到相同效果。
使用compile()
以下展示如何用新模式和新标志来重新编译正则表达式。
var regexObj = new RegExp("foo", "gi"); regexObj.compile("new foo", "g");
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) RegExp.prototype.compile |
Standard | Initial definition. Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers. |
ECMAScript Latest Draft (ECMA-262) RegExp.prototype.compile |
Draft | Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers. |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |