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
587d7db8367417b2b2512ba0 匹配除了字母和数字的所有符号 1 301353 match-everything-but-letters-and-numbers

--description--

已经了解到可以使用缩写\w来匹配字母和数字[A-Za-z0-9_]。不过,有可能想要搜寻的匹配模式是非字母数字字符。

可以使用\W搜寻和\w相反的匹配模式。注意,相反匹配模式使用大写字母。此缩写与[^A-Za-z0-9_]是一样的。

let shortHand = /\W/;
let numbers = "42%";
let sentence = "Coding!";
numbers.match(shortHand); // Returns ["%"]
sentence.match(shortHand); // Returns ["!"]

--instructions--

使用缩写\W来计算不同引号和字符串中非字母数字字符的数量。

--hints--

你的正则表达式应该使用全局状态修正符。

assert(nonAlphabetRegex.global);

你的正则表达式应该在'The five boxing wizards jump quickly.'中匹配到 6 个非字母数字字符。

assert(
  'The five boxing wizards jump quickly.'.match(nonAlphabetRegex).length == 6
);

正则表达式应该使用元字符来匹配非字母字符。

assert(/\\W/.test(nonAlphabetRegex.source));

你的正则表达式应该在'Pack my box with five dozen liquor jugs.'中匹配到 8 个非字母数字字符。

assert(
  'Pack my box with five dozen liquor jugs.'.match(nonAlphabetRegex).length == 8
);

你的正则表达式应该在'How vexingly quick daft zebras jump!'中匹配到 6 个非字母数字字符。

assert(
  'How vexingly quick daft zebras jump!'.match(nonAlphabetRegex).length == 6
);

你的正则表达式应该在'123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.'中匹配到 12 个非字母数字字符。

assert(
  '123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.'.match(nonAlphabetRegex)
    .length == 12
);

--seed--

--seed-contents--

let quoteSample = "The five boxing wizards jump quickly.";
let nonAlphabetRegex = /change/; // Change this line
let result = quoteSample.match(nonAlphabetRegex).length;

--solutions--

let quoteSample = "The five boxing wizards_jump quickly.";
let nonAlphabetRegex = /\W/g; // Change this line
let result = quoteSample.match(nonAlphabetRegex).length;