2.3 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			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--
上一次的挑戰中使用了加號 + 來查找出現一次或多次的字符。 還有一個選項可以匹配出現零次或多次的字符。
執行該操作的字符叫做星號,即*。
let soccerWord = "gooooooooal!";
let gPhrase = "gut feeling";
let oPhrase = "over the moon";
let goRegex = /go*/;
soccerWord.match(goRegex);
gPhrase.match(goRegex);
oPhrase.match(goRegex);
按順序排列,三次 match 調用將返回值 ["goooooooo"],["g"] 和 null。
--instructions--
在這個挑戰裏,chewieQuote 已經被初始化爲 Aaaaaaaaaaaaaaaarrrgh!。 創建一個變量爲 chewieRegex 的正則表達式,使用 * 在 chewieQuote 中匹配 A 及其之後出現的零個或多個a。 你的正則表達式不需要使用修飾符,也不需要匹配引號。
--hints--
你的正則表達式 chewieRegex 應該使用 * 字符來匹配零或更多的 a 字符。
assert(/\*/.test(chewieRegex.source));
正則表達式應當匹配 chewieQuote 裏的 A。
assert(result[0][0] === 'A');
你的正則表達式應該與 chewieQuote 中的字符串 Aaaaaaaaaaaaaaaa 匹配。
assert(result[0] === 'Aaaaaaaaaaaaaaaa');
你的正則表達式 chewieRegex 應該匹配 chewieQuote 中的 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);