Skip to content

正则相关章节翻译优化 #976

@Serious54088

Description

@Serious54088

str.match(regexp)

如果 regexp 带有 g 标记,则它将所有匹配项的数组作为字符串返回
If the regexp has flag g, then it returns an array of all matches as strings

按照对 match 方法的理解,作者大意为:该方法会返回一个包含所有匹配项的数组,而数组的元素类型为字符串。

感觉现在的翻译并不通顺,缩一下句:“将数组作为字符串返回”,是什么意思呢?

不知道“元素类型为字符串的数组”是不是习惯叫做“字符串数组”,也许可以翻译为“返回一个包含所有匹配项的字符串数组”?


粘性标志 "y",在位置处搜索

调用 str.match(/\w+/) 将只找到该行中的第一个单词。或者是所有带标记 g 的单词。但我们只需要在位置 4 的一个词。

  • A call to str.match(/\w+/) will find only the first word in the line (let). That’s not it.
  • We can add the flag g. But then the call str.match(/\w+/g) will look for all words in the text, while we need one word at position 4. Again, not what we need.

"所有带标记 g 的单词" 从句法上理解,让人不明所以,单词怎么会带有标记呢?感觉像是行文过度缩略的结果:所有(由)带标记 g (的正则表达式匹配到)的单词。

从现在的英文来看,作者明显重新组织了语言,中文翻译可以跟进。

Metadata

Metadata

Assignees

No one assigned

    Labels

    SolvedProblem solved

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions