Skip to content

5-regular-expressions/01-regexp-introduction/article.md and 02-regexp-methods/article.md#225

Merged
leviding merged 7 commits intojavascript-tutorial:zh-hansfrom
athena0304:5-regular-expressions/01and02
Sep 17, 2018
Merged

5-regular-expressions/01-regexp-introduction/article.md and 02-regexp-methods/article.md#225
leviding merged 7 commits intojavascript-tutorial:zh-hansfrom
athena0304:5-regular-expressions/01and02

Conversation

@athena0304
Copy link
Copy Markdown
Contributor

翻译完成
resolve #218

@BriFuture
Copy link
Copy Markdown

校对认领
@leviding

@leviding
Copy link
Copy Markdown
Member

@BriFuture 欢迎欢迎,近期本 JavaScript 教程校对有奖励积分

Copy link
Copy Markdown

@BriFuture BriFuture left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

总的来说翻译的很好,但我觉得有一些小问题,你看看我改的是否合适。另外就是有两处中英文中间没有加上空格。

另一方面,`new RegExp` 允许从字符串中动态地构造模式。

So we can figure out what we need to search and create `new RegExp` from it:
所以我们可以找出需要搜索的字段,然后从这里创建 `new RegExp`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

然后从这里创建 new RegExp => 然后根据搜索字段创建 new RegExp

我觉得这个位置的 it 指代的是前面的 what to search

正则表达式是搜索和替换字符串的一种强大方式。

In JavaScript regular expressions are implemented using objects of a built-in `RegExp` class and integrated with strings.
在JavaScript中,正则表达式使用内置的“RegExp”类的对象实现,并与字符串集成。
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

正则表达式使用内置的“RegExp”类的对象实现

这里的 using 感觉翻译成 “通过” 会不会更好点

Comment thread 5-regular-expressions/01-regexp-introduction/article.md

`m`
: Multiline mode (covered in the chapter <info:regexp-multiline>).
: 多行模式(详见 章节 <info:regexp-multiline>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

详见 章节
这个位置应该是多了个空格

1. The first search returns `-1` (not found), because the search is case-sensitive by default.
2. With the flag `pattern:/LOVE/i` the search found `match:love` at position 2.
1. 第一个搜索返回的是 `-1`(也就是没找到),因为搜索默认是区分大小写的。
2. 使用修饰符 `pattern:/LOVE/i`,搜索结果是索引为 2 的 `match:love`
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

搜索结果是索引为 2 的 match:love => 在字符串的第 2 个位置上搜索到了 match:love

alert( reg.lastIndex ); // 0 (default)
alert( str.match(reg) ); // null, not found at position 0
alert( reg.lastIndex ); // 0(默认)
alert( str.match(reg) ); // null, 但是不位置0
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但是不位置0 => 没有在位置 0 上找到匹配项

Comment thread 5-regular-expressions/02-regexp-methods/article.md Outdated
`y` 修饰符在给定位置应用一个正则表达式(或者会有很多,逐个进行),当我们理解了其中的内容后,就可以继续一步步检查文本。

Without the flag the regexp engine always searches till the end of the text, that takes time, especially if the text is large. So our parser would be very slow. The `y` flag is exactly the right thing here.
在没有该修饰符的情况下,引擎总是会检查到文本的末尾,这需要花费时间,尤其是文本很大的时候,所以解析器可能会很慢。`y` 修饰符在这里使用则恰到好处。
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这需要花费时间 => 这很费时间

`y` 修饰符在给定位置应用一个正则表达式(或者会有很多,逐个进行),当我们理解了其中的内容后,就可以继续一步步检查文本。

Without the flag the regexp engine always searches till the end of the text, that takes time, especially if the text is large. So our parser would be very slow. The `y` flag is exactly the right thing here.
在没有该修饰符的情况下,引擎总是会检查到文本的末尾,这需要花费时间,尤其是文本很大的时候,所以解析器可能会很慢。`y` 修饰符在这里使用则恰到好处。
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所以解析器可能会很慢
可能会 => 将会

## 总结,方法

Methods become much easier to understand if we separate them by their use in real-life tasks.
如果我们把这些方法通过实际任务中的使用进行拆解,就会更容易理解。
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果我们把这些方法通过实际任务中的使用进行拆解, => 如果我们按照这些方法在实际任务中的用途划分,

@leviding leviding added enhancement New feature or request and removed 校对认领 labels Sep 14, 2018
@leviding
Copy link
Copy Markdown
Member

@BriFuture 很赞,欢迎多认领本教程的校对。
@athena0304 @BriFuture 近期礼物列表也有更新喔

@leviding
Copy link
Copy Markdown
Member

@athena0304 可以修改啦

@athena0304
Copy link
Copy Markdown
Contributor Author

感谢校对者的修改意见~
@leviding 修改完毕

@BriFuture
Copy link
Copy Markdown

376 行没有对修改/保留原译文作说明,你看看,没有其它问题了 @athena0304

@BriFuture
Copy link
Copy Markdown

@leviding 修改完毕,没有问题了

@leviding leviding added WIP Work in process and removed enhancement New feature or request labels Sep 17, 2018
@leviding leviding merged commit 5e816e9 into javascript-tutorial:zh-hans Sep 17, 2018
@leviding leviding added 翻译完成 and removed WIP Work in process 正在校对 labels Sep 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants