From 01b0e12ba27b5069248fd09235e9a7143915ee30 Mon Sep 17 00:00:00 2001 From: Irvin Date: Wed, 16 Feb 2022 02:02:49 +0800 Subject: remove `notranslate` class in zh-CN --- .../reference/global_objects/regexp/index.html | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'files/zh-cn/web/javascript/reference/global_objects/regexp/index.html') 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 2a1e6ffcf5..a4ca838294 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'); // 首个参数为常规字面量的构造函数
@@ -46,7 +46,7 @@ new RegExp(/ab+c/, 'i'); // 首个参数为常规字面量的构造函数

比如,以下是等价的:

-
var re = new RegExp("\\w+");
+
var re = new RegExp("\\w+");
 var re = /\w+/;

Perl-like RegExp 属性

@@ -123,7 +123,7 @@ var re = /\w+/;

在替换的文本中,脚本中使用 $1 和 $2 指明括号里先前的匹配.

-
let re = /(\w+)\s(\w+)/;
+
let re = /(\w+)\s(\w+)/;
 let str = "John Smith";
 let newstr = str.replace(re, "$2, $1");
 console.log(newstr);
@@ -135,7 +135,7 @@ console.log(newstr);
 
 

对于不同的平台(Unix,Windows等等),其默认的行结束符是不一样的. 而下面的划分方式适用于所有平台。

-
let text = 'Some text\nAnd some more\r\nAnd yet\rThis is the end'
+
let text = 'Some text\nAnd some more\r\nAnd yet\rThis is the end'
 let lines = text.split(/\r\n|\r|\n/)
 console.log(lines) // logs [ 'Some text', 'And some more', 'And yet', 'This is the end' ]
 
@@ -144,7 +144,7 @@ console.log(lines) // logs [ 'Some text', 'And some more', 'And yet', 'This is t

在多行文本中使用正则表达式

-
let s = "Please yes\nmake my day!";
+
let s = "Please yes\nmake my day!";
 
 s.match(/yes.*day/);
 // Returns null
@@ -156,7 +156,7 @@ s.match(/yes[^]*day/);
 
 

带有{{JSxRef("Global_Objects/RegExp/sticky", "sticky")}}标志的正则表达式将会从源字符串的{{jsxref("RegExp.prototype.lastIndex")}}位置开始匹配,也就是进行“粘性匹配”。

-
let str = '#foo#'
+
let str = '#foo#'
 let regex = /foo/y
 
 regex.lastIndex = 1
@@ -169,7 +169,7 @@ regex.lastIndex      // 0 (reset after match failure)

如果正则表达式有粘性 y 标志,下一次匹配一定在 lastIndex 位置开始;如果正则表达式有全局 g 标志,下一次匹配可能在 lastIndex 位置开始,也可能在这个位置的后面开始。

-
re = /\d/y;
+
re = /\d/y;
 while (r = re.exec("123 456")) console.log(r, "AND re.lastIndex", re.lastIndex);
 
 // [ '1', index: 0, input: '123 456', groups: undefined ] AND re.lastIndex 1
@@ -187,7 +187,7 @@ while (r = re.exec("123 456")) console.log(r, "AND re.lastIndex", re.lastIndex);
 
 

下例展示了怎样从一个单词中分离出 Unicode 字符。

-
let text = "Образец text на русском языке";
+
let text = "Образец text на русском языке";
 let regex = /[\u0400-\u04FF]+/g;
 
 let match = regex.exec(text);
@@ -204,7 +204,7 @@ console.log(regex.lastIndex);  // prints "15"
 
 

从 URL 中提取子域名

-
var url = "http://xxx.domain.com";
+
var url = "http://xxx.domain.com";
 console.log(/[^.]+/.exec(url)[0].substr(7)); // logs "xxx"
 
 
@@ -248,7 +248,7 @@ console.log(/[^.]+/.exec(url)[0].substr(7)); // logs "xxx"

Starting with Gecko 34 {{geckoRelease(34)}}, in the case of a capturing group with quantifiers preventing its exercise, the matched text for a capturing group is now undefined instead of an empty string:

-
// Firefox 33 or older
+
// Firefox 33 or older
 'x'.replace(/x(.)?/g, function(m, group) {
   console.log("'group:" + group + "'");
 }); // 'group:'
-- 
cgit v1.2.3-54-g00ecf