1.5 KiB
1.5 KiB
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7db7367417b2b2512b9e | Encontrar padrões ao final da string | 1 | 301352 | match-ending-string-patterns |
--description--
No desafio anterior, você aprendeu a usar o circunflexo para capturar padrões no início de strings. Há também uma maneira de buscar padrões no fim de strings.
Se você colocar um cifrão, $
, no fim da regex, você pode buscar no fim de strings.
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);
A primeira chamada a test
retorna true
enquanto a segunda retorna false
.
--instructions--
Use o cifrão ($
) para capturar a string caboose
no fim da string caboose
.
--hints--
Você deve usar o cifrão $
na sua regex para buscar a string caboose
.
assert(lastRegex.source == 'caboose$');
A regex não deve usar nenhuma flag.
assert(lastRegex.flags == '');
Você deve capturar caboose
no fim da string The last car on a train is the 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);