Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

2.3 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7db6367417b2b2512b9a 匹配出现零次或多次的字符 1 301351 match-characters-that-occur-zero-or-more-times

--description--

上一次的挑战中使用了加号+来查找出现一次或多次的字符。还有一个选项可以匹配出现零次或多次的字符。

执行该操作的字符叫做asteriskstar,即*

let soccerWord = "gooooooooal!";
let gPhrase = "gut feeling";
let oPhrase = "over the moon";
let goRegex = /go*/;
soccerWord.match(goRegex); // Returns ["goooooooo"]
gPhrase.match(goRegex); // Returns ["g"]
oPhrase.match(goRegex); // Returns null

--instructions--

在这个挑战里,chewieQuote 已经被初始化为 "Aaaaaaaaaaaaaaaarrrgh!"。创建一个变量为chewieRegex的正则表达式,使用*符号在chewieQuote中匹配"A"及其之后出现的零个或多个"a"。你的正则表达式不需要使用修饰符,也不需要匹配引号。

--hints--

你的正则表达式chewieRegex应该使用*符号匹配'A'之后出现的零个或多个'a'字符。

assert(/\*/.test(chewieRegex.source));

正则表达式应当匹配 chewieQuote 里的 "A"

assert(result[0][0] === 'A');

你的正则表达式应该匹配'Aaaaaaaaaaaaaaaa'

assert(result[0] === 'Aaaaaaaaaaaaaaaa');

你的正则表达式chewieRegex应该匹配 16 个字符。

assert(result[0].length === 16);

你的正则表达式在'He made a fair move. Screaming about it can't help you.'中不应该匹配任何字符。

assert(
  !"He made a fair move. Screaming about it can't help you.".match(chewieRegex)
);

你的正则表达式在'Let him have it. It's not wise to upset a Wookiee.'中不应该匹配任何字符。

assert(
  !"Let him have it. It's not wise to upset a Wookiee.".match(chewieRegex)
);

--seed--

--before-user-code--

const chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";

--seed-contents--

// Only change code below this line
let chewieRegex = /change/; // Change this line
// Only change code above this line

let result = chewieQuote.match(chewieRegex);

--solutions--

  let chewieRegex = /Aa*/;
  let result = chewieQuote.match(chewieRegex);