Files
freeCodeCamp/curriculum/challenges/spanish/02-javascript-algorithms-and-data-structures/regular-expressions/find-more-than-the-first-match.spanish.md
2018-10-08 13:34:43 -04:00

2.2 KiB

id, title, localeTitle, challengeType
id title localeTitle challengeType
587d7db4367417b2b2512b93 Find More Than the First Match Encuentra más que el primer partido 1

Description

Hasta ahora, solo ha podido extraer o buscar un patrón una vez.
let testStr = "Repeat, Repeat, Repeat";
let ourRegex = /Repeat/;
testStr.match(ourRegex);
// Returns ["Repeat"]
Para buscar o extraer un patrón más de una vez, puede usar la bandera g .
let repeatRegex = /Repeat/g;
testStr.match(repeatRegex);
// Returns ["Repeat", "Repeat", "Repeat"]

Instructions

Usando el regex starRegex , encuentra y extrae ambas palabras "Twinkle" de la cadena twinkleStar . Nota
Puedes tener múltiples banderas en tu expresión regular como /search/gi

Tests

tests:
  - text: Tu regex <code>starRegex</code> debe usar la bandera global <code>g</code>
    testString: 'assert(starRegex.flags.match(/g/).length == 1, "Your regex <code>starRegex</code> should use the global flag <code>g</code>");'
  - text: Su regex <code>starRegex</code> debe usar el indicador de mayúsculas y minúsculas <code>i</code>
    testString: 'assert(starRegex.flags.match(/i/).length == 1, "Your regex <code>starRegex</code> should use the case insensitive flag <code>i</code>");'
  - text: Tu coincidencia debe coincidir con ambas apariciones de la palabra <code>&quot;Twinkle&quot;</code>
    testString: 'assert(result.sort().join() == twinkleStar.match(/twinkle/gi).sort().join(), "Your match should match both occurrences of the word <code>"Twinkle"</code>");'
  - text: El <code>result</code> tu partida debe tener dos elementos.
    testString: 'assert(result.length == 2, "Your match <code>result</code> should have two elements in it.");'

Challenge Seed

let twinkleStar = "Twinkle, twinkle, little star";
let starRegex = /change/; // Change this line
let result = twinkleStar; // Change this line

Solution

// solution required