freeCodeCamp/curriculum/challenges/japanese/02-javascript-algorithms-an.../regular-expressions/match-characters-that-occur...

2.8 KiB

id title challengeType forumTopicId dashedName
587d7db6367417b2b2512b9a 0 回以上出現する文字にマッチさせる 1 301351 match-characters-that-occur-zero-or-more-times

--description--

前回のチャレンジでは、プラス + 記号を使用して、1 回以上出現する文字を検索しました。 0 回以上出現する文字にマッチするオプションもあります。

それにはアスタリスクまたはスター * 文字を使用します。

let soccerWord = "gooooooooal!";
let gPhrase = "gut feeling";
let oPhrase = "over the moon";
let goRegex = /go*/;
soccerWord.match(goRegex);
gPhrase.match(goRegex);
oPhrase.match(goRegex);

3 つの match 呼び出しは順に、値 ["goooooooo"]["g"]null を返します。

--instructions--

このチャレンジでは、chewieQuote を文字列 Aaaaaaaaaaaaaaaarrrgh! としてすでに初期化してあります。 * 文字を使用する正規表現 chewieRegex を作成し、chewieQuote の中で、大文字 A の直後に 0 個以上の小文字 a が続く箇所にマッチさせてください。 この正規表現にフラグや文字クラスは必要ありません。また、他のどの引用符ともマッチさせないでください。

--hints--

正規表現 chewieRegex* 文字を使用して、0 個以上の文字 a にマッチさせる必要があります。

assert(/\*/.test(chewieRegex.source));

正規表現は chewieQuote にある文字列 A にマッチする必要があります。

assert(result[0][0] === 'A');

正規表現は chewieQuote にある文字列 Aaaaaaaaaaaaaaaa にマッチする必要があります。

assert(result[0] === 'Aaaaaaaaaaaaaaaa');

正規表現 chewieRegexchewieQuote にある 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);