Add translation of 9-regular-expressions/02-regexp-character-classes/article.md#675
Conversation
leviding
left a comment
There was a problem hiding this comment.
感谢提交翻译。有一些标点符号以及相关格式的使用有点小问题,我仅指出了几个代表性的,麻烦根据指出的代表性问题,检查全文并进行修改。修改完成后会进入下一步的 Review 阶段。
辛苦了。
| # 字符类 | ||
|
|
||
| Consider a practical task -- we have a phone number like `"+7(903)-123-45-67"`, and we need to turn it into pure numbers: `79035419441`. | ||
| 考虑一个实际的任务 -- 我们有一个电话号码,例如 `"+7(903)-123-45-67"`,我们需要将其转换为纯数字: `79035419441` 。 |
There was a problem hiding this comment.
| 考虑一个实际的任务 -- 我们有一个电话号码,例如 `"+7(903)-123-45-67"`,我们需要将其转换为纯数字: `79035419441` 。 | |
| 考虑一个实际的任务 — 我们有一个电话号码,例如 `"+7(903)-123-45-67"`,我们需要将其转换为纯数字:`79035419441`。 |
| 为此,我们可以查找并删除所有非数字的内容。字符类可以帮助解决这个问题。 | ||
|
|
||
| A *character class* is a special notation that matches any symbol from a certain set. | ||
| *字符类*(Character classes)是一个特殊的符号,匹配特定集中的任何符号。 |
There was a problem hiding this comment.
| *字符类*(Character classes)是一个特殊的符号,匹配特定集中的任何符号。 | |
| **字符类(Character classes)** 是一个特殊的符号,匹配特定集中的任何符号。 |
| *字符类*(Character classes)是一个特殊的符号,匹配特定集中的任何符号。 | ||
|
|
||
| For the start, let's explore the "digit" class. It's written as `pattern:\d` and corresponds to "any single digit". | ||
| 首先,让我们探索“数字”类。它写为 `pattern:\d` ,对应于“任何一个数字”。 |
There was a problem hiding this comment.
| 首先,让我们探索“数字”类。它写为 `pattern:\d` ,对应于“任何一个数字”。 | |
| 首先,让我们探索“数字”类。它写为 `pattern:\d`,对应于“任何一个数字”。 |
| ``` | ||
|
|
||
| Without the flag `pattern:g`, the regular expression only looks for the first match, that is the first digit `pattern:\d`. | ||
| 如果没有标志 `pattern:g` ,则正则表达式仅查找第一个匹配项,即第一个数字 `pattern:\d` 。 |
There was a problem hiding this comment.
| 如果没有标志 `pattern:g` ,则正则表达式仅查找第一个匹配项,即第一个数字 `pattern:\d` 。 | |
| 如果没有标志 `pattern:g`,则正则表达式仅查找第一个匹配项,即第一个数字 `pattern:\d`。 |
| `pattern:\d` ("d" is from "digit") | ||
| : A digit: a character from `0` to `9`. | ||
| `pattern:\d`("d" 来自 "digit") | ||
| :数字:从0到9的字符。 |
There was a problem hiding this comment.
| :数字:从0到9的字符。 | |
| : 数字:从0到9的字符。 |
| `pattern:\w` ("w" is from "word") | ||
| : A "wordly" character: either a letter of Latin alphabet or a digit or an underscore `_`. Non-Latin letters (like cyrillic or hindi) do not belong to `pattern:\w`. | ||
| `pattern:\w`("w" 来自 "word") | ||
| :“单字”字符:拉丁字母或数字或下划线 `_` 。非拉丁字母(如西里尔字母或印地文)不属于 `pattern:\w` 。 |
There was a problem hiding this comment.
| :“单字”字符:拉丁字母或数字或下划线 `_` 。非拉丁字母(如西里尔字母或印地文)不属于 `pattern:\w` 。 | |
| : “单字”字符:拉丁字母或数字或下划线 `_`。非拉丁字母(如西里尔字母或印地文)不属于 `pattern:\w`。 |
| - `pattern:\w` -- Latin letters, digits, underscore `'_'`. | ||
| - `pattern:\W` -- all but `pattern:\w`. | ||
| - `pattern:.` -- any character if with the regexp `'s'` flag, otherwise any except a newline `\n`. | ||
| - `pattern:\d` -- 数字。 |
There was a problem hiding this comment.
| - `pattern:\d` -- 数字。 | |
| - `pattern:\d` — 数字。 |
| - `pattern:.` -- 任何带有 `'s'` 标志的字符, 否则为除换行符 `\n` 之外的任何字符。 | ||
|
|
||
| ...But that's not all! | ||
| ...但这还不是全部! |
There was a problem hiding this comment.
| ...但这还不是全部! | |
| ……但这还不是全部! |
| ...但这还不是全部! | ||
|
|
||
| Unicode encoding, used by JavaScript for strings, provides many properties for characters, like: which language the letter belongs to (if it's a letter) it is it a punctuation sign, etc. | ||
| JavaScript用于字符串的Unicode编码提供了许多字符属性,例如:这个字母属于哪一种语言(如果它是一个字母)?它是标点符号吗?等等。 |
There was a problem hiding this comment.
| JavaScript用于字符串的Unicode编码提供了许多字符属性,例如:这个字母属于哪一种语言(如果它是一个字母)?它是标点符号吗?等等。 | |
| JavaScript 用于字符串的 Unicode 编码提供了许多字符属性,例如:这个字母属于哪一种语言(如果它是一个字母)?它是标点符号吗?等等。 |
| JavaScript用于字符串的Unicode编码提供了许多字符属性,例如:这个字母属于哪一种语言(如果它是一个字母)?它是标点符号吗?等等。 | ||
|
|
||
| We can search by these properties as well. That requires flag `pattern:u`, covered in the next article. | ||
| 我们也可以通过这些属性进行搜索。这需要标记 `pattern:u` ,在下一篇文章中介绍。 |
There was a problem hiding this comment.
| 我们也可以通过这些属性进行搜索。这需要标记 `pattern:u` ,在下一篇文章中介绍。 | |
| 我们也可以通过这些属性进行搜索。这需要标记 `pattern:u`,在下一篇文章中介绍。 |
|
Please make the requested changes. After it, add a comment "/done". |
|
/done |
| `pattern:\d` ("d" is from "digit") | ||
| : A digit: a character from `0` to `9`. | ||
| `pattern:\d`("d" 来自 "digit") | ||
| : 数字:从0到9的字符。 |
There was a problem hiding this comment.
| : 数字:从0到9的字符。 | |
| : 数字:从 `0` 到 `9` 的字符。 |
| ## 反向类 | ||
|
|
||
| For every character class there exists an "inverse class", denoted with the same letter, but uppercased. | ||
| 对于每个字符类,都有一个“反向类”,用相同的字母表示,但大写。 |
There was a problem hiding this comment.
| 对于每个字符类,都有一个“反向类”,用相同的字母表示,但大写。 | |
| 对于每个字符类,都有一个“反向类”,用相同的字母表示,但要以大写书写形式。 |
| ``` | ||
|
|
||
| ## A dot is "any character" | ||
| ## 点是“任何字符” |
There was a problem hiding this comment.
| ## 点是“任何字符” | |
| ## 点(.)是匹配“任何字符” |
| ``` | ||
|
|
||
| ### Dot as literally any character with "s" flag | ||
| ### 点字面意义上是带有"s"标志的任何字符 |
There was a problem hiding this comment.
| ### 点字面意义上是带有"s"标志的任何字符 | |
| ### 带有“s”标志时点字符类严格匹配任何字符 |
|
|
||
| ````warn header="Not supported in Firefox, IE, Edge" | ||
| Check <https://caniuse.com/#search=dotall> for the most recent state of support. At the time of writing it doesn't include Firefox, IE, Edge. | ||
| ````warn header="不支持Firefox, IE, Edge" |
There was a problem hiding this comment.
| ````warn header="不支持Firefox, IE, Edge" | |
| ````warn header="不支持 Firefox、IE、Edge" |
| ````warn header="Not supported in Firefox, IE, Edge" | ||
| Check <https://caniuse.com/#search=dotall> for the most recent state of support. At the time of writing it doesn't include Firefox, IE, Edge. | ||
| ````warn header="不支持Firefox, IE, Edge" | ||
| 检查 <https://caniuse.com/#search=dotall> 以获得最新的支持状态。在撰写本文时,它不包括Firefox,IE,Edge。 |
There was a problem hiding this comment.
| 检查 <https://caniuse.com/#search=dotall> 以获得最新的支持状态。在撰写本文时,它不包括Firefox,IE,Edge。 | |
| 使用前可从 <https://caniuse.com/#search=dotall> 确认以获得最新的支持状态。在撰写本文时,它不包括 Firefox、IE、Edge。 |
| ``` | ||
|
|
||
| Let's fix it adding spaces into the regexp `pattern:\d - \d`: | ||
| 让我们修复它,在regexp模式中添加空格:\ d-\ d`: |
There was a problem hiding this comment.
| 让我们修复它,在regexp模式中添加空格:\ d-\ d`: | |
| 让我们修复一下,在正则表达式中添加空格:\ d-\ d`: |
| 但是,如果正则表达式未考虑空格,则可能无法正常工作。 | ||
|
|
||
| Let's try to find digits separated by a hyphen: | ||
| 让我们尝试查找由连字符分隔的数字: |
There was a problem hiding this comment.
| 让我们尝试查找由连字符分隔的数字: | |
| 让我们尝试查找由连字符(-)分隔的数字: |
| JavaScript 用于字符串的 Unicode 编码提供了许多字符属性,例如:这个字母属于哪一种语言(如果它是一个字母)?它是标点符号吗?等等。 | ||
|
|
||
| We can search by these properties as well. That requires flag `pattern:u`, covered in the next article. | ||
| 我们也可以通过这些属性进行搜索。这需要标记 `pattern:u`,在下一篇文章中介绍。 |
There was a problem hiding this comment.
| 我们也可以通过这些属性进行搜索。这需要标记 `pattern:u`,在下一篇文章中介绍。 | |
| 我们也可以通过这些属性进行搜索。这需要标志 `pattern:u`,在下一篇文章中介绍。 |
|
Please make the requested changes. After it, add a comment "/done". |
|
/done |
|
辛苦大家啦~ |
目标章节:9-regular-expressions/02-regexp-character-classes
当前上游最新 commit:javascript-tutorial/en.javascript.info@162280b
本 PR 所做更改如下: