From 012ee621791b6895e637f96e6523027951768f25 Mon Sep 17 00:00:00 2001 From: Irvin Date: Wed, 16 Feb 2022 02:03:27 +0800 Subject: remove inline style for zh-CN --- .../global_objects/regexp/exec/index.html | 2 +- .../reference/global_objects/regexp/index.html | 4 +- .../global_objects/regexp/lastindex/index.html | 57 ++++++++++------------ 3 files changed, 28 insertions(+), 35 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/global_objects/regexp') diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/exec/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/exec/index.html index b7e9edf7ec..8ee22ffa6c 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/exec/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/exec/index.html @@ -14,7 +14,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/exec

exec() 方法在一个指定字符串中执行一个搜索匹配。返回一个结果数组或 {{jsxref("null")}}。

-

在设置了 {{jsxref("RegExp.global", "global")}} 或 {{jsxref("RegExp.sticky", "sticky")}} 标志位的情况下(如 /foo/g or /foo/y),JavaScript {{jsxref("RegExp")}} 对象是有状态的。他们会将上次成功匹配后的位置记录在 {{jsxref("RegExp.lastIndex", "lastIndex")}} 属性中。使用此特性,exec() 可用来对单个字符串中的多次匹配结果进行逐条的遍历(包括捕获到的匹配),而相比之下, {{jsxref("String.prototype.match()")}} 只会返回匹配到的结果。

+

在设置了 {{jsxref("RegExp.global", "global")}} 或 {{jsxref("RegExp.sticky", "sticky")}} 标志位的情况下(如 /foo/g or /foo/y),JavaScript {{jsxref("RegExp")}} 对象是有状态的。他们会将上次成功匹配后的位置记录在 {{jsxref("RegExp.lastIndex", "lastIndex")}} 属性中。使用此特性,exec() 可用来对单个字符串中的多次匹配结果进行逐条的遍历(包括捕获到的匹配),而相比之下, {{jsxref("String.prototype.match()")}} 只会返回匹配到的结果。

如果你只是为了判断是否匹配(true或 false),可以使用 {{jsxref("RegExp.test()")}} 方法,或者 {{jsxref("String.search()")}} 方法。

diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/index.html index a4ca838294..a0bcd500de 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/index.html @@ -30,7 +30,7 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp

以下三种表达式都会创建相同的正则表达式:

-
/ab+c/i; //字面量形式
+
/ab+c/i; //字面量形式
 new RegExp('ab+c', 'i'); // 首个参数为字符串模式的构造函数
 new RegExp(/ab+c/, 'i'); // 首个参数为常规字面量的构造函数
@@ -213,7 +213,7 @@ console.log(/[^.]+/.exec(url)[0].substr(7)); // logs "xxx"

使用浏览器内建的URL API而非正则表达式来解析URL是更好的做法

-

规范

+

规范

diff --git a/files/zh-cn/web/javascript/reference/global_objects/regexp/lastindex/index.html b/files/zh-cn/web/javascript/reference/global_objects/regexp/lastindex/index.html index f7e667288f..92dadc8159 100644 --- a/files/zh-cn/web/javascript/reference/global_objects/regexp/lastindex/index.html +++ b/files/zh-cn/web/javascript/reference/global_objects/regexp/lastindex/index.html @@ -10,41 +10,34 @@ translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex ---
{{JSRef("Global_Objects", "RegExp")}}
-

概述

+

概述

lastIndex 是正则表达式的一个可读可写的整型属性,用来指定下一次匹配的起始索引。

{{js_property_attributes(1,0,0)}}
-

语法

-
lastIndex = regExpObj.lastIndex;
-

描述

+

语法

+
lastIndex = regExpObj.lastIndex;
+

描述

只有正则表达式使用了表示全局检索的 "g" 标志时,该属性才会起作用。此时应用下面的规则:

-

示例

+

示例

考虑下面的语句:

var re = /(hi)?/g;
-
-  
+

匹配空字符串

console.log(re.exec("hi"));
 console.log(re.lastIndex);
-
-  
-
-  
+

返回 ["hi", "hi"] ,lastIndex 等于 2。

console.log(re.exec("hi"));
 console.log(re.lastIndex);
-
-  
-
-  
+

返回 ["", undefined],即一个数组,其第 0 个元素为匹配的字符串。此种情况下为空字符串,是因为 lastIndex 为 2(且一直是 2),"hi" 长度为 2。

-

规范

+

规范

@@ -70,18 +63,18 @@ console.log(re.lastIndex);
-

浏览器兼容性

+

浏览器兼容性

{{ CompatibilityTable() }}

- - - - - - + + + + + + @@ -98,13 +91,13 @@ console.log(re.lastIndex);
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafariFeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support
- - - - - - - + + + + + + + @@ -118,7 +111,7 @@ console.log(re.lastIndex);
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari MobileFeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support
-

相关链接

+

相关链接