2.2 KiB
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
let testStr = "Repeat, Repeat, Repeat";Para buscar o extraer un patrón más de una vez, puede usar la bandera
let ourRegex = /Repeat/;
testStr.match(ourRegex);
// Returns ["Repeat"]
g
.
let repeatRegex = /Repeat/g;
testStr.match(repeatRegex);
// Returns ["Repeat", "Repeat", "Repeat"]
Instructions
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>"Twinkle"</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