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

2.2 KiB

id title challengeType videoUrl localeTitle
587d7db7367417b2b2512b9e Match Ending String Patterns 1 Coincidir con patrones de cadena

Description

En el último desafío, aprendiste a usar el carácter de caret para buscar patrones al principio de las cadenas. También hay una forma de buscar patrones al final de las cadenas. Puede buscar el final de las cadenas con el dollar sign $ al final de la expresión regular.
Let theEnding = "Esta es una historia interminable";
Deje storyRegex = / story $ /;
storyRegex.test (theEnding);
// Devuelve true
Deje que noEnding = "A veces una historia tenga que terminar";
storyRegex.test (noEnding);
// Devuelve falso

Instructions

Utilice el carácter de ancla ( $ ) para que coincida con la cadena "caboose" al final de la cadena caboose .

Tests

tests:
  - text: Debe buscar <code>&quot;caboose&quot;</code> con el signo de dólar <code>$</code> ancla en su expresión regular.
    testString: 'assert(lastRegex.source == "caboose$", "You should search for <code>"caboose"</code> with the dollar sign <code>$</code> anchor in your regex.");'
  - text: Su expresión regular no debe usar ninguna bandera.
    testString: 'assert(lastRegex.flags == "", "Your regex should not use any flags.");'
  - text: Debe coincidir con <code>&quot;caboose&quot;</code> al final de la cadena <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