--- title: RegExp.prototype.compile() slug: Web/JavaScript/Reference/Global_Objects/RegExp/compile tags: - Deprecated - JavaScript translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/compile ---
已废弃的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 |
---|---|---|
{{SpecName('ES6', '#sec-regexp.prototype.compile', 'RegExp.prototype.compile')}} | {{Spec2('ES6')}} | Initial definition. Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers. |
{{SpecName('ESDraft', '#sec-regexp.prototype.compile', 'RegExp.prototype.compile')}} | {{Spec2('ESDraft')}} | Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers. |
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |