1.8 KiB
1.8 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7db7367417b2b2512b9e | 末尾の文字列パターンにマッチさせる | 1 | 301352 | match-ending-string-patterns |
--description--
前回のチャレンジでは、キャレット文字を使用して文字列の先頭にあるパターンを検索することを学びました。 文字列の末尾でパターンを検索する方法もあります。
正規表現の末尾でドル記号 $
を使用すると、文字列の末尾を検索できます。
let theEnding = "This is a never ending story";
let storyRegex = /story$/;
storyRegex.test(theEnding);
let noEnding = "Sometimes a story will have to end";
storyRegex.test(noEnding);
最初の test
呼び出しは true
を返し、2 番目の呼び出しは false
を返します。
--instructions--
アンカー文字 ($
) を使用して、文字列 caboose
の末尾にある文字列 caboose
にマッチさせてください。
--hints--
正規表現で末尾にドル記号 $
を使用して caboose
を検索する必要があります。
assert(lastRegex.source == 'caboose$');
正規表現でフラグを使用しないでください。
assert(lastRegex.flags == '');
文字列 The last car on a train is the caboose
の末尾にある caboose
にマッチさせる必要があります。
lastRegex.lastIndex = 0;
assert(lastRegex.test('The last car on a train is the caboose'));
--seed--
--seed-contents--
let caboose = "The last car on a train is the caboose";
let lastRegex = /change/; // Change this line
let result = lastRegex.test(caboose);
--solutions--
let caboose = "The last car on a train is the caboose";
let lastRegex = /caboose$/; // Change this line
let result = lastRegex.test(caboose);