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.0 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
5c3dda8b4d8df89bea71600f 檢查混合字符組 1 301339 check-for-mixed-grouping-of-characters

--description--

有時候我們想使用正則表達式裏的括號 () 來檢查字符組。

如果想在字符串找到 PenguinPumpkin,可以用這個正則表達式:/P(engu|umpk)in/g

然後使用 test() 方法檢查 test 字符串裏面是否包含字符組。

let testStr = "Pumpkin";
let testRegex = /P(engu|umpk)in/;
testRegex.test(testStr);

test 方法會返回 true

--instructions--

完善正則表達式,使其以區分大小寫的方式檢查 Franklin RooseveltEleanor Roosevelt 的名字,並且應該忽略 middle names。

然後完善代碼,使創建的正則檢查 myString,根據正則是否匹配返回 truefalse

--hints--

正則 myRegex 測試 Franklin D. Roosevelt 應該返回 true

myRegex.lastIndex = 0;
assert(myRegex.test('Franklin D. Roosevelt'));

正則 myRegex 測試 Eleanor Roosevelt 應該返回 true

myRegex.lastIndex = 0;
assert(myRegex.test('Eleanor Roosevelt'));

正則 myRegex 測試 Franklin Rosevelt 應該返回 false

myRegex.lastIndex = 0;
assert(!myRegex.test('Franklin Rosevelt'));

正則 myRegex 測試 Frank Roosevelt 應該返回 false

myRegex.lastIndex = 0;
assert(!myRegex.test('Frank Roosevelt'));

你應該使用 .test() 方法來檢測正則表達式。

assert(code.match(/myRegex.test\(\s*myString\s*\)/));

你的返回結果應該爲 true

assert(result === true);

--seed--

--seed-contents--

let myString = "Eleanor Roosevelt";
let myRegex = /False/; // Change this line
let result = false; // Change this line
// After passing the challenge experiment with myString and see how the grouping works

--solutions--

let myString = "Eleanor Roosevelt";
let myRegex = /(Franklin|Eleanor).*Roosevelt/;
let result = myRegex.test(myString);