Files
Nicholas Carrigan (he/him) 3da4be21bb chore: seed chinese traditional (#42005)
Seeds the chinese traditional files manually so we can deploy to
staging.
2021-05-05 22:43:49 +05:30

2.4 KiB
Raw Permalink Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7db5367417b2b2512b95 將單個字符與多種可能性匹配 1 301357 match-single-character-with-multiple-possibilities

--description--

已經瞭解了文字匹配模式(/literal/)和通配符(/./)。 這是正則表達式的兩種極端情況,一種是精確匹配,而另一種則是匹配所有。 在這兩種極端情況之間有一個平衡選項。

可以使用字符集 character classes)更靈活的匹配字符。 可以把字符集放在方括號([])之間來定義一組需要匹配的字符串。

例如,如果想要匹配 bagbigbug,但是不想匹配 bog。 可以創建正則表達式 /b[aiu]g/ 來執行此操作。 [aiu] 是隻匹配字符 ai 或者 u 的字符集。

let bigStr = "big";
let bagStr = "bag";
let bugStr = "bug";
let bogStr = "bog";
let bgRegex = /b[aiu]g/;
bigStr.match(bgRegex);
bagStr.match(bgRegex);
bugStr.match(bgRegex);
bogStr.match(bgRegex);

按順序排列,四次 match 調用將返回值 ["big"]["bag"]["bug"]null

--instructions--

使用元音字符集(aeiou)在正則表達式 vowelRegex 中匹配到字符串 quoteSample 中的所有元音。

**注意:**一定要同時匹配大小寫元音。

--hints--

你應該匹配到所有25個元音。

assert(result.length == 25);

你的正則表達式 vowelRegex 應該使用字符集。

assert(/\[.*\]/.test(vowelRegex.source));

你的正則表達式 vowelRegex 應該使用全局標誌。

assert(vowelRegex.flags.match(/g/).length == 1);

你的正則表達式 vowelRegex 應該使用忽略大小寫標誌。

assert(vowelRegex.flags.match(/i/).length == 1);

你的正則表達式不應該匹配任何輔音。

assert(!/[b-df-hj-np-tv-z]/gi.test(result.join()));

--seed--

--seed-contents--

let quoteSample = "Beware of bugs in the above code; I have only proved it correct, not tried it.";
let vowelRegex = /change/; // Change this line
let result = vowelRegex; // Change this line

--solutions--

let quoteSample = "Beware of bugs in the above code; I have only proved it correct, not tried it.";
let vowelRegex = /[aeiou]/gi; // Change this line
let result = quoteSample.match(vowelRegex); // Change this line