Skip to content

feat: add translation of 9-regular-expressions/14-regexp-lookahead-lookbehind task and solution#974

Merged
leviding merged 8 commits intojavascript-tutorial:masterfrom
xdsnet:master
Feb 5, 2022
Merged

feat: add translation of 9-regular-expressions/14-regexp-lookahead-lookbehind task and solution#974
leviding merged 8 commits intojavascript-tutorial:masterfrom
xdsnet:master

Conversation

@xdsnet
Copy link
Copy Markdown
Contributor

@xdsnet xdsnet commented Nov 29, 2021

目标章节:例如 9-regular-expressions/14-regexp-lookahead-lookbehind

当前上游最新 commit:此处填写本项目英文版 https://github.com/javascript-tutorial/en.javascript.info 的最新 commit,例如 javascript-tutorial/en.javascript.info@f452810

本 PR 所做更改如下:

文件名 参考上游 commit 更改(理由)
1-find-non-negative-integers ce3b892 重新翻译
2-insert-after-head ce3b892 重新翻译

该翻译可以关闭 #973

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Nov 29, 2021

CLA assistant check
All committers have signed the CLA.

@xdsnet
Copy link
Copy Markdown
Contributor Author

xdsnet commented Nov 29, 2021

I have read the CLA Document and I hereby sign the CLA

@leviding leviding changed the title 翻译9-regular-expressions/14-regexp-lookahead-lookbehind 下的任务部分内容 Translate task and solution of 9-regular-expressions/14-regexp-lookahead-lookbehind Dec 4, 2021
@leviding leviding changed the title Translate task and solution of 9-regular-expressions/14-regexp-lookahead-lookbehind Translate tasks of 9-regular-expressions/14-regexp-lookahead-lookbehind Dec 4, 2021
Copy link
Copy Markdown
Collaborator

@bemself bemself left a comment

Choose a reason for hiding this comment

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

感谢翻译!

正则中对于一个整数可以简单的表示为 `表达式:\d+`.

The regexp for an integer number is `pattern:\d+`.
我们可以通过在它前面加上否定的前瞻来排除不正确的情况: `表达式:(?<!-)\d+`.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

exclude negatives by: 这里的 negatives 我认为是负数,译文用的是“不正确的情况”似乎范围偏广了些。

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

另外,句号问题

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

关于 negative lookahead 的翻译,建议全篇统一一下,参考第 15 行的 comment

```

As you can see, it matches `match:8`, from `subject:-18`. To exclude it, we need to ensure that the regexp starts matching a number not from the middle of another (non-matching) number.
你会发现, 从 `-18`中配到了 `8`,要排除这种情况,我们需要确保我们的正则表达式要从合适的位置开始匹配一个数字,而不是从另一个(不匹配)数字的后面开始匹配。
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[从 -18中配到了 8,要] -> [ 从 -18 中配到了 8,要] ,注意必要的空格和中文标点符号

你会发现, 从 `-18`中配到了 `8`,要排除这种情况,我们需要确保我们的正则表达式要从合适的位置开始匹配一个数字,而不是从另一个(不匹配)数字的后面开始匹配。

We can do it by specifying another negative lookbehind: `pattern:(?<!-)(?<!\d)\d+`. Now `pattern:(?<!\d)` ensures that a match does not start after another digit, just what we need.
我们可以通过指定另一个负查找来实现: `表达式:(?<!-)(?<!\d)\d+`. 现在 `表达式:(?<!\d)` 确保匹配不会在另一个数字之后开始,这正是我们需要的。
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nagative lookbehind: 我感觉翻译成“负查”稍显简单模糊了些,没有体现出”向后“的意思。翻了下网络,个人比较倾向于译成 ”后行否定断言“,虽然也挺别捏的。。。

另外第一个句号不是中文的句号。

这里有一个包含整数的字符串。

Create a regexp that looks for only non-negative ones (zero is allowed).
创建一个正则表达式来找出所有的非负整数 (0也是非负整数)。
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
创建一个正则表达式来找出所有的非负整数 (0也是非负整数)
创建一个正则表达式来找出所有的非负整数(0 也是非负整数)

@@ -1,29 +1,31 @@

Для того, чтобы вставить после тега `<body>`, нужно вначале его найти. Будем использовать регулярное выражение `pattern:<body.*>`.
为了在`<body>`标记之后插入,我们必须首先找到它。我们可以使用正则表达式模式`<body.*?>`来实现这一点。
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
为了在`<body>`标记之后插入,我们必须首先找到它。我们可以使用正则表达式模式`<body.*?>`来实现这一点。
为了在 `<body>` 标记之后插入,我们必须首先找到它。我们可以使用正则表达式模式 `<body.*?>` 来实现这一点。


Происходит замена "пустой строки", перед которой идёт `pattern:<body.*>` на `<h1>Hello</h1>`. Что, как раз, и есть вставка этой строки после `<body>`.
这个标签 `<body.*?>`在这里并没有作为捕获返回,实际上它匹配到了一个在`<body.*?>`后的空字符串(位置)。
因此,它将紧接`<body.*?>`的“空行”替换为`<h1>Hello</h1>`。这样就在`<body>`之后插入了内容。
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
因此,它将紧接`<body.*?>`的“空行”替换为`<h1>Hello</h1>`。这样就在`<body>`之后插入了内容。
因此,它将紧接 `<body.*?>` 的“空行”替换为 `<h1>Hello</h1>`。这样就在 `<body>` 之后插入了内容。

因此,它将紧接`<body.*?>`的“空行”替换为`<h1>Hello</h1>`。这样就在`<body>`之后插入了内容。

P.S. Этому регулярному выражению не помешают флаги: `pattern:/<body.*>/si`, чтобы в "точку" входил перевод строки (тег может занимать несколько строк), а также чтобы теги в другом регистре типа `match:<BODY>` тоже находились.
P.S. 正则式中单标记如`s` 和 `i` 也经常被使用,如: `/<body.*?>/si`. 这里 `s`标记使得 `.`可以匹配换行符,而`i` 标记表示大小写不敏感,即 `<body>` 和 `<BODY>`都可以被匹配。
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
P.S. 正则式中单标记如`s``i` 也经常被使用,如: `/<body.*?>/si`. 这里 `s`标记使得 `.`可以匹配换行符,而`i` 标记表示大小写不敏感,即 `<body>``<BODY>`都可以被匹配。
另外,正则表达式中的标记如 `s``i` 也经常被使用,如: `/<body.*?>/si`这里 `s` 标记使得 `.` 可以匹配换行符,而 `i` 标记表示大小写不敏感,即 `<body>``<BODY>` 都可以被匹配。

# 在标签头后插入

Есть строка с HTML-документом.
我们有一个带有HTML文档的字符串。
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
我们有一个带有HTML文档的字符串
我们有一个带有 HTML 文档的字符串

我们有一个带有HTML文档的字符串。

Вставьте после тега `<body>` (у него могут быть атрибуты) строку `<h1>Hello</h1>`.
编写一个正则表达式,在`<body>`标记之后立即插入`<h1>Hello</h1>`。标记可能具有属性。
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
编写一个正则表达式,在`<body>`标记之后立即插入`<h1>Hello</h1>`。标记可能具有属性。
编写一个正则表达式,在 `<body>` 标记之后立即插入 `<h1>Hello</h1>`。标记可能具有属性。

```

После этого значение `str`:
在此之后,`str`的值应为:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
在此之后,`str`的值应为:
在此之后,`str` 的值应为:

@javascript-translate-bot
Copy link
Copy Markdown

Please make the requested changes. After it, add a comment "/done".
Then I'll ask for a new review 👻

@leviding leviding changed the title Translate tasks of 9-regular-expressions/14-regexp-lookahead-lookbehind feat: add translation of 9-regular-expressions/14-regexp-lookahead-lookbehind task and solution Feb 5, 2022
@leviding leviding merged commit 0d7776a into javascript-tutorial:master Feb 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants