From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../global_objects/regexp/compile/index.html | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/regexp/compile/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/regexp/compile/index.html') diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/compile/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/compile/index.html new file mode 100644 index 0000000000..e5b080a839 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/compile/index.html @@ -0,0 +1,131 @@ +--- +title: RegExp.prototype.compile() +slug: Web/JavaScript/Reference/Global_Objects/RegExp/compile +tags: + - Deprecated + - JavaScript +translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/compile +--- +
{{JSRef}} {{deprecated_header}}
+ +

已废弃的compile() 方法被用于在脚本执行过程中(重新)编译正则表达式。与RegExp构造函数基本一样。

+ +

语法

+ +
regexObj.compile(pattern, flags)
+ +

参数

+ +
+
pattern
+
正则表达式的文本 。
+
flags
+
+

如果指定,标志可以具有以下值的任意组合:

+ +
+
g
+
全局匹配
+
i
+
忽略大小写
+
m
+
多行;让开始和结束字符(^ 和 $)工作在多行模式工作(例如,^ 和 $ 可以匹配字符串中每一行的开始和结束(行是由 \n 或 \r 分割的),而不只是整个输入字符串的最开始和最末尾处。
+
y
+
黏度; 在目标字符串中,只从正则表达式的lastIndex属性指定的显示位置开始匹配(并且不试图从任何之后的索引匹配)。
+
+
+
+ +

描述

+ +

不推荐compile方法。你可以使用 RegExp 构造函数来得到相同效果。

+ +

示例

+ +

使用compile()

+ +

以下展示如何用新模式和新标志来重新编译正则表达式。

+ +
var regexObj = new RegExp("foo", "gi");
+regexObj.compile("new foo", "g");
+
+ +

规范

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{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.
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}{{CompatVersionUnknown}}
+
+ +

相关链接

+ + -- cgit v1.2.3-54-g00ecf