Kristofer Koishigawa b3213fc892 fix(i18n): chinese test suite (#38220)
* fix: Chinese test suite

Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working.

* fix: ran script, updated testStrings and solutions
2020-03-03 18:49:47 +05:30

2.1 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
587d7dbb367417b2b2512bab Use Capture Groups to Search and Replace 1 使用捕获组进行搜索和替换

Description

搜索很有用。但是,当它也更改(或替换)您匹配的文本时,您可以使搜索功能更强大。您可以在字符串上使用.replace()搜索和替换字符串中的文本。 .replace()的输入首先是您要搜索的正则表达式模式。第二个参数是用于替换匹配的字符串或用于执行某些操作的函数。
let wrongText =“天空是银色的。”;
让silverRegex = / silver /;
wrongText.replacesilverRegex“blue”;
//返回“天空是蓝色的”。
您还可以使用美元符号( $ )访问替换字符串中的捕获组。
“Code Camp”.replace/\ w +\ s\ w +/'$ 2 $ 1';
//返回“营地代码”

Instructions

写一个正则表达式,以便它搜索字符串"good" 。然后更新replaceText变量,将"good"替换为"okey-dokey"

Tests

tests:
  - text: 您应该使用<code>.replace()</code>来搜索和替换。
    testString: assert(code.match(/\.replace\(.*\)/));
  - text: 你的正则表达式应该改变<code>&quot;This sandwich is good.&quot;</code> <code>&quot;This sandwich is okey-dokey.&quot;</code>
    testString: assert(result == "This sandwich is okey-dokey." && replaceText === "okey-dokey");
  - text: 你不应该改变最后一行。
    testString: assert(code.match(/result\s*=\s*huhText\.replace\(.*?\)/));

Challenge Seed

let huhText = "This sandwich is good.";
let fixRegex = /change/; // Change this line
let replaceText = ""; // Change this line
let result = huhText.replace(fixRegex, replaceText);

Solution

// solution required