-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Translation/5-09-regexp-groups #257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3d23a7a
d0e74df
9ad9a0f
d3fcfb0
7a49f10
4988a8c
ec112ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| A regexp to search 3-digit color `#abc`: `pattern:/#[a-f0-9]{3}/i`. | ||
| 查找三位颜色 `#abc` 的正则表达式为:`pattern:/#[a-f0-9]{3}/i`。 | ||
|
|
||
| We can add exactly 3 more optional hex digits. We don't need more or less. Either we have them or we don't. | ||
| 我们可以添加额外三位 16 进制数,不多也不少。这三位可能有,也可能没有。 | ||
|
|
||
| The simplest way to add them -- is to append to the regexp: `pattern:/#[a-f0-9]{3}([a-f0-9]{3})?/i` | ||
| 最简单的方式 —— 直接附加上去:`pattern:/#[a-f0-9]{3}([a-f0-9]{3})?/i`。 | ||
|
|
||
| We can do it in a smarter way though: `pattern:/#([a-f0-9]{3}){1,2}/i`. | ||
| 但是,还有一种更讨巧的方法:`pattern:/#([a-f0-9]{3}){1,2}/i`。 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我们可以用一种更加妙的方法:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 用『讨巧』也可以吧 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 『讨巧』中文意思为『取巧,不费力气而得到好处』,用在这里我认为并没有什么不妥。翻译是给人看的,如果非要照字典的话,为什么不用机翻? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 讨巧一词,讨为动词,有渴求,请求的意思,我认为已经上下级的身份不对了。 @Moonliujk 请帮忙校对。
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 没问题的,翻译风格不同而已 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| Here the regexp `pattern:[a-f0-9]{3}` is in parentheses to apply the quantifier `pattern:{1,2}` to it as a whole. | ||
| 这里我们把正则 `pattern:[a-f0-9]{3}` 放置在括号内,并且应用量词 `pattern:{1,2}`。 | ||
|
|
||
| In action: | ||
| 实际操作: | ||
|
|
||
| ```js run | ||
| let reg = /#([a-f0-9]{3}){1,2}/gi; | ||
|
|
@@ -18,7 +18,7 @@ let str = "color: #3f3; background-color: #AA00ef; and: #abcd"; | |
| alert( str.match(reg) ); // #3f3 #AA0ef #abc | ||
| ``` | ||
|
|
||
| There's minor problem here: the pattern found `match:#abc` in `subject:#abcd`. To prevent that we can add `pattern:\b` to the end: | ||
| 不过这里有个小问题:这个模式会在 `subject:#abcd` 中找到 `match:#abc`。为了避免这种情况,我们可以在最后加上 `pattern:\b`: | ||
|
|
||
| ```js run | ||
| let reg = /#([a-f0-9]{3}){1,2}\b/gi; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
最简单的方式 —— 在正则表达式后附加上去: