freeCodeCamp/curriculum/challenges/portuguese/02-javascript-algorithms-an.../regular-expressions/match-ending-string-pattern...

2.2 KiB

id title challengeType videoUrl localeTitle
587d7db7367417b2b2512b9e Match Ending String Patterns 1 Padrões de Sequência de Correspondência Final

Description

No último desafio, você aprendeu a usar o caractere de caret para procurar padrões no início das seqüências de caracteres. Há também uma maneira de procurar padrões no final das strings. Você pode pesquisar o final das strings usando o caractere de dollar sign $ no final da regex.
deixe theEnding = "Esta é uma história sem fim";
deixe storyRegex = / story $ /;
storyRegex.test (theEnding);
// Retorna true
deixe noEnding = "Às vezes uma história terá que terminar";
storyRegex.test (noEnding);
// Retorna falso

Instructions

Use o caractere de âncora ( $ ) para combinar com a string "caboose" no final do caboose string.

Tests

tests:
  - text: Você deve procurar por <code>&quot;caboose&quot;</code> com o cifrão <code>$</code> anchor no seu regex.
    testString: 'assert(lastRegex.source == "caboose$", "You should search for <code>"caboose"</code> with the dollar sign <code>$</code> anchor in your regex.");'
  - text: Seu regex não deve usar sinalizadores.
    testString: 'assert(lastRegex.flags == "", "Your regex should not use any flags.");'
  - text: Você deve combinar <code>&quot;caboose&quot;</code> no final da corda <code>&quot;The last car on a train is the caboose&quot;</code>
    testString: 'assert(lastRegex.test("The last car on a train is the caboose"), "You should match <code>"caboose"</code> at the end of the string <code>"The last car on a train is the caboose"</code>");'

Challenge Seed

let caboose = "The last car on a train is the caboose";
let lastRegex = /change/; // Change this line
let result = lastRegex.test(caboose);

Solution

// solution required