docs: add Spanish docs
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
---
|
||||
id: 587d7dba367417b2b2512ba8
|
||||
title: Check for All or None
|
||||
localeTitle: Comprobar por todos o ninguno
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
A veces, los patrones que desea buscar pueden tener partes que pueden o no existir. Sin embargo, puede ser importante verificarlos de todas formas.
|
||||
Puede especificar la posible existencia de un elemento con un signo de interrogación, <code>?</code> . Esto comprueba si hay cero o uno de los elementos anteriores. Puede pensar que este símbolo dice que el elemento anterior es opcional.
|
||||
Por ejemplo, hay ligeras diferencias entre el inglés americano y el británico y puede usar el signo de interrogación para hacer coincidir ambas ortografías.
|
||||
<blockquote>let american = "color";<br>let british = "colour";<br>let rainbowRegex= /colou?r/;<br>rainbowRegex.test(american); // Returns true<br>rainbowRegex.test(british); // Returns true</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Cambie el regex <code>favRegex</code> para que coincida con la versión del inglés americano (favorito) y del inglés británico (favorito) de la palabra.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: 'Su expresión regular debe utilizar el símbolo opcional, <code>?</code> .
|
||||
testString: 'assert(favRegex.source.match(/\?/).length > 0, "Your regex should use the optional symbol, <code>?</code>.");'
|
||||
- text: Tu expresión regular debe coincidir con <code>"favorite"</code>
|
||||
testString: 'assert(favRegex.test("favorite"), "Your regex should match <code>"favorite"</code>");'
|
||||
- text: Tu expresión regular debe coincidir con <code>"favourite"</code>
|
||||
testString: 'assert(favRegex.test("favourite"), "Your regex should match <code>"favourite"</code>");'
|
||||
- text: Tu expresión regular no debe coincidir con <code>"fav"</code>
|
||||
testString: 'assert(!favRegex.test("fav"), "Your regex should not match <code>"fav"</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let favWord = "favorite";
|
||||
let favRegex = /change/; // Change this line
|
||||
let result = favRegex.test(favWord);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,59 @@
|
||||
---
|
||||
id: 587d7db4367417b2b2512b92
|
||||
title: Extract Matches
|
||||
localeTitle: Extraer fósforos
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Hasta ahora, solo ha estado comprobando si existe un patrón o no dentro de una cadena. También puede extraer las coincidencias reales que encontró con el método <code>.match()</code> .
|
||||
Para usar el método <code>.match()</code> , aplique el método en una cadena y pase la expresión regular dentro de los paréntesis. Aquí hay un ejemplo:
|
||||
<blockquote>"Hello, World!".match(/Hello/);<br>// Returns ["Hello"]<br>let ourStr = "Regular expressions";<br>let ourRegex = /expressions/;<br>ourStr.match(ourRegex);<br>// Returns ["expressions"]</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Aplique el método <code>.match()</code> para extraer la <code>coding</code> palabras.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: El <code>result</code> debe tener la palabra <code>coding</code>
|
||||
testString: 'assert(result.join() === "coding", "The <code>result</code> should have the word <code>coding</code>");'
|
||||
- text: Tu regex <code>codingRegex</code> debería buscar la <code>coding</code>
|
||||
testString: 'assert(codingRegex.source === "coding", "Your regex <code>codingRegex</code> should search for <code>coding</code>");'
|
||||
- text: Deberías usar el método <code>.match()</code> .
|
||||
testString: 'assert(code.match(/\.match\(.*\)/), "You should use the <code>.match()</code> method.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let extractStr = "Extract the word 'coding' from this string.";
|
||||
let codingRegex = /change/; // Change this line
|
||||
let result = extractStr; // Change this line
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,56 @@
|
||||
---
|
||||
id: 587d7db6367417b2b2512b9b
|
||||
title: Find Characters with Lazy Matching
|
||||
localeTitle: Encuentra personajes con Lazy Matching
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
En expresiones regulares, una coincidencia <code>greedy</code> encuentra la parte más larga posible de una cadena que se ajusta al patrón de expresiones regulares y la devuelve como una coincidencia. La alternativa se denomina coincidencia <code>lazy</code> , que encuentra la parte más pequeña posible de la cadena que satisface el patrón de expresiones regulares.
|
||||
Puede aplicar la expresión regular <code>/t[az]*i/</code> a la cadena <code>"titanic"</code> . Esta expresión regular es básicamente un patrón que comienza con <code>t</code> , termina con <code>i</code> y tiene algunas letras en medio.
|
||||
Las expresiones regulares son por defecto <code>greedy</code> , por lo que la coincidencia devolvería <code>["titani"]</code> . Encuentra la subcadena más grande posible para ajustar el patrón.
|
||||
Sin embargo, puedes usar el <code>?</code> Personaje para cambiarlo a juego <code>lazy</code> . <code>"titanic"</code> emparejado contra la expresión regular ajustada de <code>/t[az]*?i/</code> devuelve <code>["ti"]</code> .
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
<code>/<.*>/</code> la expresión regular <code>/<.*>/</code> para devolver la etiqueta HTML <code><h1></code> y no el texto <code>"<h1>Winter is coming</h1>"</code> . Recuerda el comodín <code>.</code> En una expresión regular coincide con cualquier carácter.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: La variable de <code>result</code> debe ser una matriz con <code><h1></code> en ella
|
||||
testString: 'assert(result[0] == "<h1>", "The <code>result</code> variable should be an array with <code><h1></code> in it");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let text = "<h1>Winter is coming</h1>";
|
||||
let myRegex = /<.*>/; // Change this line
|
||||
let result = text.match(myRegex);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,63 @@
|
||||
---
|
||||
id: 587d7db4367417b2b2512b93
|
||||
title: Find More Than the First Match
|
||||
localeTitle: Encuentra más que el primer partido
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Hasta ahora, solo ha podido extraer o buscar un patrón una vez.
|
||||
<blockquote>let testStr = "Repeat, Repeat, Repeat";<br>let ourRegex = /Repeat/;<br>testStr.match(ourRegex);<br>// Returns ["Repeat"]</blockquote>
|
||||
Para buscar o extraer un patrón más de una vez, puede usar la bandera <code>g</code> .
|
||||
<blockquote>let repeatRegex = /Repeat/g;<br>testStr.match(repeatRegex);<br>// Returns ["Repeat", "Repeat", "Repeat"]</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Usando el regex <code>starRegex</code> , encuentra y extrae ambas palabras <code>"Twinkle"</code> de la cadena <code>twinkleStar</code> .
|
||||
<strong>Nota</strong> <br> Puedes tener múltiples banderas en tu expresión regular como <code>/search/gi</code>
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
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.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let twinkleStar = "Twinkle, twinkle, little star";
|
||||
let starRegex = /change/; // Change this line
|
||||
let result = twinkleStar; // Change this line
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,74 @@
|
||||
---
|
||||
id: 587d7db7367417b2b2512b9c
|
||||
title: Find One or More Criminals in a Hunt
|
||||
localeTitle: Encuentra uno o más criminales en una cacería
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Tiempo para pausar y probar sus nuevas habilidades de escritura de expresiones regulares. Un grupo de criminales escapó de la cárcel y se escapó, pero no sabes cuántos. Sin embargo, sí sabes que permanecen juntos cuando están cerca de otras personas. Eres responsable de encontrar a todos los criminales a la vez.
|
||||
Aquí hay un ejemplo para revisar cómo hacer esto:
|
||||
La expresión regular <code>/z+/</code> coincide con la letra <code>z</code> cuando aparece una o más veces seguidas. Encontraría coincidencias en todas las cadenas siguientes:
|
||||
<blockquote>"z"<br>"zzzzzz"<br>"ABCzzzz"<br>"zzzzABC"<br>"abczzzzzzzzzzzzzzzzzzzzzabc"</blockquote>
|
||||
Pero no encuentra coincidencias en las siguientes cadenas ya que no hay caracteres de la letra <code>z</code> :
|
||||
<blockquote>""<br>"ABC"<br>"abcabc"</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Escriba una expresión regular <code>greedy</code> que encuentre uno o más delincuentes dentro de un grupo de otras personas. Un criminal está representado por la letra mayúscula <code>C</code>
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular debe coincidir con <code>one</code> criminal (" <code>C</code> ") en <code>"C"</code>
|
||||
testString: 'assert("C".match(reCriminals) && "C".match(reCriminals)[0] == "C", "Your regex should match <code>one</code> criminal ("<code>C</code>") in <code>"C"</code>");'
|
||||
- text: Su expresión regular debe coincidir con <code>two</code> delincuentes (" <code>CC</code> ") en <code>"CC"</code>
|
||||
testString: 'assert("CC".match(reCriminals) && "CC".match(reCriminals)[0] == "CC", "Your regex should match <code>two</code> criminals ("<code>CC</code>") in <code>"CC"</code>");'
|
||||
- text: Su expresión regular debe coincidir con <code>three</code> delincuentes (" <code>CCC</code> ") en <code>"P1P5P4CCCP2P6P3"</code>
|
||||
testString: 'assert("P1P5P4CCCP2P6P3".match(reCriminals) && "P1P5P4CCCP2P6P3".match(reCriminals)[0] == "CCC", "Your regex should match <code>three</code> criminals ("<code>CCC</code>") in <code>"P1P5P4CCCP2P6P3"</code>");'
|
||||
- text: Su expresión regular debe coincidir con <code>five</code> delincuentes (" <code>CCCCC</code> ") en <code>"P6P2P7P4P5CCCCCP3P1"</code>
|
||||
testString: 'assert("P6P2P7P4P5CCCCCP3P1".match(reCriminals) && "P6P2P7P4P5CCCCCP3P1".match(reCriminals)[0] == "CCCCC", "Your regex should match <code>five</code> criminals ("<code>CCCCC</code>") in <code>"P6P2P7P4P5CCCCCP3P1"</code>");'
|
||||
- text: Tu expresión regular no debe coincidir con ningún criminal en <code>""</code>
|
||||
testString: 'assert(!reCriminals.test(""), "Your regex should not match any criminals in <code>""</code>");'
|
||||
- text: Su expresión regular no debe coincidir con ningún criminal en <code>"P1P2P3"</code>
|
||||
testString: 'assert(!reCriminals.test("P1P2P3"), "Your regex should not match any criminals in <code>"P1P2P3"</code>");'
|
||||
- text: Su expresión regular debe coincidir con <code>fifty</code> delincuentes (" <code>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC</code> ") en <code>"P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3"</code> .
|
||||
testString: 'assert("P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3".match(reCriminals) && "P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3".match(reCriminals)[0] == "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC", "Your regex should match <code>fifty</code> criminals ("<code>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC</code>") in <code>"P2P1P5P4CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCP3"</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
// example crowd gathering
|
||||
let crowd = 'P1P2P3P4P5P6CCCP7P8P9';
|
||||
|
||||
let reCriminals = /./; // Change this line
|
||||
|
||||
let matchedCriminals = crowd.match(reCriminals);
|
||||
console.log(matchedCriminals);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,73 @@
|
||||
---
|
||||
id: 587d7db4367417b2b2512b91
|
||||
title: Ignore Case While Matching
|
||||
localeTitle: Ignorar caso mientras coinciden
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Hasta ahora, has visto expresiones regulares para hacer coincidencias literales de cadenas. Pero a veces, es posible que también desee igualar las diferencias de casos.
|
||||
Caso (o, a veces, mayúsculas) es la diferencia entre letras mayúsculas y minúsculas. Ejemplos de mayúsculas son <code>"A"</code> , <code>"B"</code> y <code>"C"</code> . Ejemplos de minúsculas son <code>"a"</code> , <code>"b"</code> y <code>"c"</code> .
|
||||
Puedes hacer coincidir ambos casos usando lo que se llama una bandera. Hay otras banderas, pero aquí se enfocará en la bandera que ignora el caso, la bandera <code>i</code> . Puedes usarlo añadiéndolo a la expresión regular. Un ejemplo de uso de esta bandera es <code>/ignorecase/i</code> . Esta expresión regular puede coincidir con las cadenas <code>"ignorecase"</code> , <code>"igNoreCase"</code> e <code>"IgnoreCase"</code> .
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Escriba una expresión regular <code>fccRegex</code> para que coincida con <code>"freeCodeCamp"</code> , sin importar su caso. Su expresión regular no debe coincidir con ninguna abreviatura o variación con espacios.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Tu expresión regular debe coincidir con <code>freeCodeCamp</code>
|
||||
testString: 'assert(fccRegex.test("freeCodeCamp"), "Your regex should match <code>freeCodeCamp</code>");'
|
||||
- text: Tu expresión regular debe coincidir con <code>FreeCodeCamp</code>
|
||||
testString: 'assert(fccRegex.test("FreeCodeCamp"), "Your regex should match <code>FreeCodeCamp</code>");'
|
||||
- text: Tu expresión regular debe coincidir con <code>FreecodeCamp</code>
|
||||
testString: 'assert(fccRegex.test("FreecodeCamp"), "Your regex should match <code>FreecodeCamp</code>");'
|
||||
- text: Tu expresión regular debe coincidir con <code>FreeCodecamp</code>
|
||||
testString: 'assert(fccRegex.test("FreeCodecamp"), "Your regex should match <code>FreeCodecamp</code>");'
|
||||
- text: Su expresión regular no debe coincidir con <code>Free Code Camp</code>
|
||||
testString: 'assert(!fccRegex.test("Free Code Camp"), "Your regex should not match <code>Free Code Camp</code>");'
|
||||
- text: Tu expresión regular debe coincidir con <code>FreeCOdeCamp</code>
|
||||
testString: 'assert(fccRegex.test("FreeCOdeCamp"), "Your regex should match <code>FreeCOdeCamp</code>");'
|
||||
- text: Su expresión regular no debe coincidir con <code>FCC</code>
|
||||
testString: 'assert(!fccRegex.test("FCC"), "Your regex should not match <code>FCC</code>");'
|
||||
- text: Tu expresión regular debe coincidir con <code>FrEeCoDeCamp</code>
|
||||
testString: 'assert(fccRegex.test("FrEeCoDeCamp"), "Your regex should match <code>FrEeCoDeCamp</code>");'
|
||||
- text: Tu expresión regular debe coincidir con <code>FrEeCodECamp</code>
|
||||
testString: 'assert(fccRegex.test("FrEeCodECamp"), "Your regex should match <code>FrEeCodECamp</code>");'
|
||||
- text: Tu expresión regular debe coincidir con <code>FReeCodeCAmp</code>
|
||||
testString: 'assert(fccRegex.test("FReeCodeCAmp"), "Your regex should match <code>FReeCodeCAmp</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let myString = "freeCodeCamp";
|
||||
let fccRegex = /change/; // Change this line
|
||||
let result = fccRegex.test(myString);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,68 @@
|
||||
---
|
||||
id: 587d7db4367417b2b2512b90
|
||||
title: Match a Literal String with Different Possibilities
|
||||
localeTitle: Unir una cadena literal con diferentes posibilidades
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Usando expresiones regulares como <code>/coding/</code> , puede buscar el patrón <code>"coding"</code> en otra cadena.
|
||||
Esto es poderoso para buscar cadenas simples, pero está limitado a un solo patrón. Puede buscar múltiples patrones utilizando la <code>alternation</code> u operador <code>OR</code> : <code>|</code> .
|
||||
Este operador hace coincidir los patrones antes o después de él. Por ejemplo, si desea hacer coincidir <code>"yes"</code> o <code>"no"</code> , la expresión regular que desea es <code>/yes|no/</code> .
|
||||
También puede buscar más de dos patrones. Puede hacer esto agregando más patrones con más operadores <code>OR</code> que los separan, como <code>/yes|no|maybe/</code> .
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Complete el regex <code>petRegex</code> para que coincida con las mascotas <code>"dog"</code> , <code>"cat"</code> , <code>"bird"</code> o <code>"fish"</code> .
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su regex <code>petRegex</code> debe devolver <code>true</code> para la cadena <code>"John has a pet dog."</code>
|
||||
testString: 'assert(petRegex.test("John has a pet dog."), "Your regex <code>petRegex</code> should return <code>true</code> for the string <code>"John has a pet dog."</code>");'
|
||||
- text: Su regex <code>petRegex</code> debe devolver <code>false</code> para la cadena <code>"Emma has a pet rock."</code>
|
||||
testString: 'assert(!petRegex.test("Emma has a pet rock."), "Your regex <code>petRegex</code> should return <code>false</code> for the string <code>"Emma has a pet rock."</code>");'
|
||||
- text: Tu regex <code>petRegex</code> debe devolver <code>true</code> para la cadena <code>"Emma has a pet bird."</code>
|
||||
testString: 'assert(petRegex.test("Emma has a pet bird."), "Your regex <code>petRegex</code> should return <code>true</code> for the string <code>"Emma has a pet bird."</code>");'
|
||||
- text: Tu regex <code>petRegex</code> debe devolver <code>true</code> para la cadena <code>"Liz has a pet cat."</code>
|
||||
testString: 'assert(petRegex.test("Liz has a pet cat."), "Your regex <code>petRegex</code> should return <code>true</code> for the string <code>"Liz has a pet cat."</code>");'
|
||||
- text: Su regex <code>petRegex</code> debe devolver <code>false</code> para la cadena <code>"Kara has a pet dolphin."</code>
|
||||
testString: 'assert(!petRegex.test("Kara has a pet dolphin."), "Your regex <code>petRegex</code> should return <code>false</code> for the string <code>"Kara has a pet dolphin."</code>");'
|
||||
- text: Su regex <code>petRegex</code> debe devolver <code>true</code> para la cadena <code>"Alice has a pet fish."</code>
|
||||
testString: 'assert(petRegex.test("Alice has a pet fish."), "Your regex <code>petRegex</code> should return <code>true</code> for the string <code>"Alice has a pet fish."</code>");'
|
||||
- text: Su regex <code>petRegex</code> debe devolver <code>false</code> para la cadena <code>"Jimmy has a pet computer."</code>
|
||||
testString: 'assert(!petRegex.test("Jimmy has a pet computer."), "Your regex <code>petRegex</code> should return <code>false</code> for the string <code>"Jimmy has a pet computer."</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let petString = "James has a pet cat.";
|
||||
let petRegex = /change/; // Change this line
|
||||
let result = petRegex.test(petString);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,66 @@
|
||||
---
|
||||
id: 587d7db7367417b2b2512b9f
|
||||
title: Match All Letters and Numbers
|
||||
localeTitle: Unir todas las letras y números
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Al usar clases de caracteres, pudo buscar todas las letras del alfabeto con <code>[az]</code> . Este tipo de clase de caracteres es lo suficientemente común como para que haya un atajo, aunque también incluye algunos caracteres adicionales.
|
||||
La clase de caracteres más cercana en JavaScript para que coincida con el alfabeto es <code>\w</code> . Este atajo es igual a <code>[A-Za-z0-9_]</code> . Esta clase de caracteres coincide con mayúsculas y minúsculas más números. Tenga en cuenta que esta clase de caracteres también incluye el carácter de subrayado ( <code>_</code> ).
|
||||
<blockquote>let longHand = /[A-Za-z0-9_]+/;<br>let shortHand = /\w+/;<br>let numbers = "42";<br>let varNames = "important_var";<br>longHand.test(numbers); // Returns true<br>shortHand.test(numbers); // Returns true<br>longHand.test(varNames); // Returns true<br>shortHand.test(varNames); // Returns true</blockquote>
|
||||
Estas clases de caracteres de acceso directo también se conocen como <code>shorthand character classes</code> .
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Use la clase de caracteres abreviados <code>\w</code> para contar el número de caracteres alfanuméricos en varias comillas y cadenas.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular debe utilizar la bandera global.
|
||||
testString: 'assert(alphabetRegexV2.global, "Your regex should use the global flag.");'
|
||||
- text: Tu expresión regular debe usar el carácter abreviado
|
||||
testString: 'assert(/\\w/.test(alphabetRegexV2.source), "Your regex should use the shorthand character <code>\w</code> to match all characters which are alphanumeric.");'
|
||||
- text: Su expresión regular debe encontrar 31 caracteres alfanuméricos en <code clase = "notranslate"> "Los cinco magos de boxeo saltan rápidamente". </code>
|
||||
testString: 'assert("The five boxing wizards jump quickly.".match(alphabetRegexV2).length === 31, "Your regex should find 31 alphanumeric characters in <code>"The five boxing wizards jump quickly."</code>");'
|
||||
- text: Su expresión regular debe encontrar 32 caracteres alfanuméricos en <code clase = "notranslate"> "Empaque mi caja con cinco docenas de jarras de licor". </code>
|
||||
testString: 'assert("Pack my box with five dozen liquor jugs.".match(alphabetRegexV2).length === 32, "Your regex should find 32 alphanumeric characters in <code>"Pack my box with five dozen liquor jugs."</code>");'
|
||||
- text: Tu expresión regular debe encontrar 30 caracteres alfanuméricos en <code clase = "notranslate"> "¡Cómo saltan las cebras!" </code>
|
||||
testString: 'assert("How vexingly quick daft zebras jump!".match(alphabetRegexV2).length === 30, "Your regex should find 30 alphanumeric characters in <code>"How vexingly quick daft zebras jump!"</code>");'
|
||||
- text: Su expresión regular debe encontrar 36 caracteres alfanuméricos en <código clase = "notranslate"> "123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ." </code>
|
||||
testString: 'assert("123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.".match(alphabetRegexV2).length === 36, "Your regex should find 36 alphanumeric characters in <code>"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let quoteSample = "The five boxing wizards jump quickly.";
|
||||
let alphabetRegexV2 = /change/; // Change this line
|
||||
let result = quoteSample.match(alphabetRegexV2).length;
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,68 @@
|
||||
---
|
||||
id: 587d7db8367417b2b2512ba1
|
||||
title: Match All Non-Numbers
|
||||
localeTitle: Coincidir con todos los no números
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
El último desafío mostró cómo buscar dígitos usando el método abreviado <code>\d</code> con una minúscula <code>d</code> . También puede buscar no dígitos usando un atajo similar que use una <code>D</code> mayúscula en su lugar.
|
||||
El atajo para buscar caracteres sin dígitos es <code>\D</code> Esto es igual a la clase de caracteres <code>[^0-9]</code> , que busca un solo carácter que no sea un número entre cero y nueve.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Use la clase de caracteres abreviados para no dígitos <code>\D</code> para contar cuántos no dígitos hay en los títulos de las películas.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular debe usar el carácter de acceso directo para hacer coincidir los caracteres que no son dígitos
|
||||
testString: 'assert(/\\D/.test(noNumRegex.source), "Your regex should use the shortcut character to match non-digit characters");'
|
||||
- text: Su expresión regular debe utilizar la bandera global.
|
||||
testString: 'assert(noNumRegex.global, "Your regex should use the global flag.");'
|
||||
- text: Su expresión regular no debe encontrar dígitos que no sean dígitos en <code class = "notranslate"> "9" </code>.
|
||||
testString: 'assert("9".match(noNumRegex) == null, "Your regex should find no non-digits in <code>"9"</code>.");'
|
||||
- text: Su expresión regular debe encontrar 6 no dígitos en <code class = "notranslate"> "Catch 22" </code>.
|
||||
testString: 'assert("Catch 22".match(noNumRegex).length == 6, "Your regex should find 6 non-digits in <code>"Catch 22"</code>.");'
|
||||
- text: Su expresión regular debe encontrar 11 no dígitos en <code class = "notranslate"> "101 Dalmatians" </code>.
|
||||
testString: 'assert("101 Dalmatians".match(noNumRegex).length == 11, "Your regex should find 11 non-digits in <code>"101 Dalmatians"</code>.");'
|
||||
- text: 'Su expresión regular debe encontrar 15 no dígitos en <código clase = "notranslate"> "Uno, dos, tres" </code>.'
|
||||
testString: 'assert("One, Two, Three".match(noNumRegex).length == 15, "Your regex should find 15 non-digits in <code>"One, Two, Three"</code>.");'
|
||||
- text: Su expresión regular debe encontrar 12 no dígitos en <code class = "notranslate"> "21 Jump Street" </code>.
|
||||
testString: 'assert("21 Jump Street".match(noNumRegex).length == 12, "Your regex should find 12 non-digits in <code>"21 Jump Street"</code>.");'
|
||||
- text: "Su expresión regular debe encontrar 17 dígitos que no sean dígitos en <code class =" notranslate ">" 2001: A Space Odyssey "</code>. '
|
||||
testString: 'assert("2001: A Space Odyssey".match(noNumRegex).length == 17, "Your regex should find 17 non-digits in <code>"2001: A Space Odyssey"</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let numString = "Your sandwich will be $5.00";
|
||||
let noNumRegex = /change/; // Change this line
|
||||
let result = numString.match(noNumRegex).length;
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,68 @@
|
||||
---
|
||||
id: 5d712346c441eddfaeb5bdef
|
||||
title: Match All Numbers
|
||||
localeTitle: Coincidir todos los números
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Ha aprendido atajos para patrones de cadena comunes como alfanuméricos. Otro patrón común es buscar solo dígitos o números.
|
||||
El atajo para buscar caracteres de dígitos es <code>\d</code> , con una minúscula <code>d</code> . Esto es igual a la clase de caracteres <code>[0-9]</code> , que busca un solo carácter de cualquier número entre cero y nueve.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Use la clase de caracteres abreviados <code>\d</code> para contar cuántos dígitos hay en los títulos de las películas. Los números escritos ("seis" en lugar de 6) no cuentan.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Tu expresión regular debe usar el atajo para coincidir con los dígitos.
|
||||
testString: 'assert(/\\d/.test(numRegex.source), "Your regex should use the shortcut character to match digit characters");'
|
||||
- text: Su expresión regular debe utilizar la bandera global.
|
||||
testString: 'assert(numRegex.global, "Your regex should use the global flag.");'
|
||||
- text: Su expresión regular debe encontrar 1 dígito en <code clase = "notranslate"> "9" </code>.
|
||||
testString: 'assert("9".match(numRegex).length == 1, "Your regex should find 1 digit in <code>"9"</code>.");'
|
||||
- text: Su expresión regular debe encontrar 2 dígitos en <code class = "notranslate"> "Catch 22" </code>.
|
||||
testString: 'assert("Catch 22".match(numRegex).length == 2, "Your regex should find 2 digits in <code>"Catch 22"</code>.");'
|
||||
- text: Su expresión regular debe encontrar 3 dígitos en <code class = "notranslate"> "101 Dalmatians" </code>.
|
||||
testString: 'assert("101 Dalmatians".match(numRegex).length == 3, "Your regex should find 3 digits in <code>"101 Dalmatians"</code>.");'
|
||||
- text: 'Su expresión regular no debe encontrar dígitos en <code class = "notranslate"> "One, Two, Three" </code>.'
|
||||
testString: 'assert("One, Two, Three".match(numRegex) == null, "Your regex should find no digits in <code>"One, Two, Three"</code>.");'
|
||||
- text: Su expresión regular debe encontrar 2 dígitos en <code clase = "notranslate"> "21 Jump Street" </code>.
|
||||
testString: 'assert("21 Jump Street".match(numRegex).length == 2, "Your regex should find 2 digits in <code>"21 Jump Street"</code>.");'
|
||||
- text: 'Su expresión regular debe encontrar 4 dígitos en <code class = "notranslate"> "2001: A Space Odyssey" </code>.'
|
||||
testString: 'assert("2001: A Space Odyssey".match(numRegex).length == 4, "Your regex should find 4 digits in <code>"2001: A Space Odyssey"</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let numString = "Your sandwich will be $5.00";
|
||||
let numRegex = /change/; // Change this line
|
||||
let result = numString.match(numRegex).length;
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,73 @@
|
||||
---
|
||||
id: 587d7db5367417b2b2512b94
|
||||
title: Match Anything with Wildcard Period
|
||||
localeTitle: Coincidir cualquier cosa con el período de comodín
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
A veces no (o no es necesario) conocer los caracteres exactos en sus patrones. Pensar en todas las palabras que coinciden, por ejemplo, una falta de ortografía llevaría mucho tiempo. Por suerte, se puede ahorrar tiempo utilizando el carácter comodín: <code>.</code>
|
||||
El carácter comodín <code>.</code> coincidirá con cualquier personaje. El comodín es también llamado <code>dot</code> y <code>period</code> . Puede usar el carácter comodín como cualquier otro carácter en la expresión regular. Por ejemplo, si desea hacer coincidir <code>"hug"</code> , <code>"huh"</code> , <code>"hut"</code> y <code>"hum"</code> , puede usar la expresión regular <code>/hu./</code> para hacer coincidir las cuatro palabras.
|
||||
<blockquote>let humStr = "I'll hum a song";<br>let hugStr = "Bear hug";<br>let huRegex = /hu./;<br>humStr.match(huRegex); // Returns ["hum"]<br>hugStr.match(huRegex); // Returns ["hug"]</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Complete la expresión regular <code>unRegex</code> para que coincida con las cadenas <code>"run"</code> , <code>"sun"</code> , <code>"fun"</code> , <code>"pun"</code> , <code>"nun"</code> y <code>"bun"</code> . Su expresión regular debe utilizar el carácter comodín.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Deberías usar el método <code>.test()</code> .
|
||||
testString: 'assert(code.match(/\.test\(.*\)/), "You should use the <code>.test()</code> method.");'
|
||||
- text: Debe utilizar el carácter comodín en su expresión regular <code>unRegex</code>
|
||||
testString: 'assert(/\./.test(unRegex.source), "You should use the wildcard character in your regex <code>unRegex</code>");'
|
||||
- text: Su expresión regular <code>unRegex</code> debe coincidir con <code>"run"</code> en <code>"Let us go on a run."</code>
|
||||
testString: 'assert(unRegex.test("Let us go on a run."), "Your regex <code>unRegex</code> should match <code>"run"</code> in <code>"Let us go on a run."</code>");'
|
||||
- text: Su expresión regular <code>unRegex</code> debe coincidir con <code>"sun"</code> en <code>"The sun is out today."</code>
|
||||
testString: 'assert(unRegex.test("The sun is out today."), "Your regex <code>unRegex</code> should match <code>"sun"</code> in <code>"The sun is out today."</code>");'
|
||||
- text: Su expresión regular <code>unRegex</code> debe coincidir con <code>"fun"</code> en <code>"Coding is a lot of fun."</code>
|
||||
testString: 'assert(unRegex.test("Coding is a lot of fun."), "Your regex <code>unRegex</code> should match <code>"fun"</code> in <code>"Coding is a lot of fun."</code>");'
|
||||
- text: Su expresión regular <code>unRegex</code> debe coincidir con <code>"pun"</code> en <code>"Seven days without a pun makes one weak."</code>
|
||||
testString: 'assert(unRegex.test("Seven days without a pun makes one weak."), "Your regex <code>unRegex</code> should match <code>"pun"</code> in <code>"Seven days without a pun makes one weak."</code>");'
|
||||
- text: Tu expresión regular <code>unRegex</code> debe coincidir con <code>"nun"</code> en <code>"One takes a vow to be a nun."</code>
|
||||
testString: 'assert(unRegex.test("One takes a vow to be a nun."), "Your regex <code>unRegex</code> should match <code>"nun"</code> in <code>"One takes a vow to be a nun."</code>");'
|
||||
- text: Tu regex <code>unRegex</code> debe coincidir con <code>"bun"</code> en <code>"She got fired from the hot dog stand for putting her hair in a bun."</code>
|
||||
testString: 'assert(unRegex.test("She got fired from the hot dog stand for putting her hair in a bun."), "Your regex <code>unRegex</code> should match <code>"bun"</code> in <code>"She got fired from the hot dog stand for putting her hair in a bun."</code>");'
|
||||
- text: Su expresión regular <code>unRegex</code> no debe coincidir con <code>"There is a bug in my code."</code>
|
||||
testString: 'assert(!unRegex.test("There is a bug in my code."), "Your regex <code>unRegex</code> should not match <code>"There is a bug in my code."</code>");'
|
||||
- text: Tu expresión regular <code>unRegex</code> no debe coincidir con <code>"Catch me if you can."</code>
|
||||
testString: 'assert(!unRegex.test("Can me if you can."), "Your regex <code>unRegex</code> should not match <code>"Catch me if you can."</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let exampleStr = "Let's have fun with regular expressions!";
|
||||
let unRegex = /change/; // Change this line
|
||||
let result = unRegex.test(exampleStr);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,61 @@
|
||||
---
|
||||
id: 587d7db7367417b2b2512b9d
|
||||
title: Match Beginning String Patterns
|
||||
localeTitle: Emparejar patrones de cuerdas que comienzan
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Los desafíos anteriores mostraron que las expresiones regulares se pueden usar para buscar una serie de coincidencias. También se utilizan para buscar patrones en posiciones específicas en cadenas.
|
||||
En un desafío anterior, <code>caret</code> carácter de <code>caret</code> ( <code>^</code> ) dentro de un <code>character set</code> para crear un <code>negated character set</code> en la forma <code>[^thingsThatWillNotBeMatched]</code> . Fuera de un <code>character set</code> , el <code>caret</code> se utiliza para buscar patrones al principio de las cadenas.
|
||||
<blockquote>let firstString = "Ricky is first and can be found.";<br>let firstRegex = /^Ricky/;<br>firstRegex.test(firstString);<br>// Returns true<br>let notFirst = "You can't find Ricky now.";<br>firstRegex.test(notFirst);<br>// Returns false</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Use el carácter de <code>caret</code> en una expresión regular para encontrar <code>"Cal"</code> solo al principio de la cadena <code>rickyAndCal</code> .
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular debe buscar <code>"Cal"</code> con una letra mayúscula.
|
||||
testString: 'assert(calRegex.source == "^Cal", "Your regex should search for <code>"Cal"</code> with a capital letter.");'
|
||||
- text: Su expresión regular no debe usar ninguna bandera.
|
||||
testString: 'assert(calRegex.flags == "", "Your regex should not use any flags.");'
|
||||
- text: Tu expresión regular debe coincidir con <code>"Cal"</code> al principio de la cadena.
|
||||
testString: 'assert(calRegex.test("Cal and Ricky both like racing."), "Your regex should match <code>"Cal"</code> at the beginning of the string.");'
|
||||
- text: Su expresión regular no debe coincidir con <code>"Cal"</code> en medio de una cadena.
|
||||
testString: 'assert(!calRegex.test("Ricky and Cal both like racing."), "Your regex should not match <code>"Cal"</code> in the middle of a string.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let rickyAndCal = "Cal and Ricky both like racing.";
|
||||
let calRegex = /change/; // Change this line
|
||||
let result = calRegex.test(rickyAndCal);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,60 @@
|
||||
---
|
||||
id: 587d7db6367417b2b2512b99
|
||||
title: Match Characters that Occur One or More Times
|
||||
localeTitle: Relacionar los caracteres que ocurren una o más veces
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
A veces, debe hacer coincidir un carácter (o grupo de caracteres) que aparece una o más veces seguidas. Esto significa que ocurre al menos una vez, y puede repetirse.
|
||||
Puede utilizar el carácter <code>+</code> para comprobar si ese es el caso. Recuerda, el personaje o patrón tiene que estar presente consecutivamente. Es decir, el personaje tiene que repetir uno tras otro.
|
||||
Por ejemplo, <code>/a+/g</code> encontraría una coincidencia en <code>"abc"</code> y devolvería <code>["a"]</code> . Debido al <code>+</code> , también encontraría una única coincidencia en <code>"aabc"</code> y devolvería <code>["aa"]</code> .
|
||||
Si se comprueba en lugar de la cadena <code>"abab"</code> , sería encontrar dos partidos y volver <code>["a", "a"]</code> , porque los <code>a</code> caracteres que no están en una fila - no es un <code>b</code> entre ellos. Finalmente, dado que no hay <code>"a"</code> a <code>"a"</code> en la cadena <code>"bcd"</code> , no encontrará una coincidencia.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Desea encontrar coincidencias cuando la letra <code>s</code> aparece una o más veces en <code>"Mississippi"</code> . Escribe una expresión regular que use el signo <code>+</code> .
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular <code>myRegex</code> debe utilizar el <code>+</code> signo para que coincida con uno o más <code>s</code> caracteres.
|
||||
testString: 'assert(/\+/.test(myRegex.source), "Your regex <code>myRegex</code> should use the <code>+</code> sign to match one or more <code>s</code> characters.");'
|
||||
- text: Tu regex <code>myRegex</code> debe coincidir con 2 elementos.
|
||||
testString: 'assert(result.length == 2, "Your regex <code>myRegex</code> should match 2 items.");'
|
||||
- text: La variable de <code>result</code> debe ser una matriz con dos coincidencias de <code>"ss"</code>
|
||||
testString: 'assert(result[0] == "ss" && result[1] == "ss", "The <code>result</code> variable should be an array with two matches of <code>"ss"</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let difficultSpelling = "Mississippi";
|
||||
let myRegex = /change/; // Change this line
|
||||
let result = difficultSpelling.match(myRegex);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,63 @@
|
||||
---
|
||||
id: 587d7db6367417b2b2512b9a
|
||||
title: Match Characters that Occur Zero or More Times
|
||||
localeTitle: Caracteres de coincidencia que ocurren cero o más veces
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
El último desafío usó el signo más <code>+</code> para buscar caracteres que aparecen una o más veces. También hay una opción que coincide con los caracteres que aparecen cero o más veces.
|
||||
El personaje para hacer esto es el <code>asterisk</code> o <code>star</code> : <code>*</code> .
|
||||
<blockquote>let soccerWord = "gooooooooal!";<br>let gPhrase = "gut feeling";<br>let oPhrase = "over the moon";<br>let goRegex = /go*/;<br>soccerWord.match(goRegex); // Returns ["goooooooo"]<br>gPhrase.match(goRegex); // Returns ["g"]<br>oPhrase.match(goRegex); // Returns null</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Cree un regex <code>chewieRegex</code> que use el carácter <code>*</code> para que coincida con todos los caracteres <code>"a"</code> superiores e inferiores en <code>chewieQuote</code> . Su expresión regular no necesita indicadores y no debe coincidir con ninguna de las otras comillas.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular <code>chewieRegex</code> debe utilizar el <code>*</code> carácter a cero o más <code>a</code> personajes.
|
||||
testString: 'assert(/\*/.test(chewieRegex.source), "Your regex <code>chewieRegex</code> should use the <code>*</code> character to match zero or more <code>a</code> characters.");'
|
||||
- text: Tu regex <code>chewieRegex</code> debe coincidir con 16 caracteres.
|
||||
testString: 'assert(result[0].length === 16, "Your regex <code>chewieRegex</code> should match 16 characters.");'
|
||||
- text: Tu expresión regular debe coincidir con <code>"Aaaaaaaaaaaaaaaa"</code> .
|
||||
testString: 'assert(result[0] === "Aaaaaaaaaaaaaaaa", "Your regex should match <code>"Aaaaaaaaaaaaaaaa"</code>.");'
|
||||
- text: 'Tu expresión regular no debe coincidir con ningún carácter en <code>"He made a fair move. Screaming about it can't help you."</code> '
|
||||
testString: 'assert(!"He made a fair move. Screaming about it can\"t help you.".match(chewieRegex), "Your regex should not match any characters in <code>"He made a fair move. Screaming about it can't help you."</code>");'
|
||||
- text: "Tu expresión regular no debe coincidir con ningún carácter en <code>"Let him have it. It's not wise to upset a Wookiee."</code> '
|
||||
testString: 'assert(!"Let him have it. It\"s not wise to upset a Wookiee.".match(chewieRegex), "Your regex should not match any characters in <code>"Let him have it. It's not wise to upset a Wookiee."</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let chewieQuote = "Aaaaaaaaaaaaaaaarrrgh!";
|
||||
let chewieRegex = /change/; // Change this line
|
||||
let result = chewieQuote.match(chewieRegex);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,59 @@
|
||||
---
|
||||
id: 587d7db7367417b2b2512b9e
|
||||
title: Match Ending String Patterns
|
||||
localeTitle: Coincidir con patrones de cadena
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
En el último desafío, aprendiste a usar el carácter de <code>caret</code> 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 <code>dollar sign</code> <code>$</code> al final de la expresión regular.
|
||||
<blockquote>let theEnding = "This is a never ending story";<br>let storyRegex = /story$/;<br>storyRegex.test(theEnding);<br>// Returns true<br>let noEnding = "Sometimes a story will have to end";<br>storyRegex.test(noEnding);<br>// Returns false<br></blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Use el carácter de ancla ( <code>$</code> ) para que coincida con la cadena <code>"caboose"</code> al final de la cadena <code>caboose</code> .
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Debe buscar <code>"caboose"</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>"caboose"</code> al final de la cadena <code>"The last car on a train is the caboose"</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>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let caboose = "The last car on a train is the caboose";
|
||||
let lastRegex = /change/; // Change this line
|
||||
let result = lastRegex.test(caboose);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,65 @@
|
||||
---
|
||||
id: 587d7db8367417b2b2512ba0
|
||||
title: Match Everything But Letters and Numbers
|
||||
localeTitle: Unir todo, excepto letras y números
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Ha aprendido que puede usar un atajo para hacer coincidir los caracteres alfanuméricos <code>[A-Za-z0-9_]</code> usando <code>\w</code> . Un patrón natural que quizás desee buscar es el opuesto a los alfanuméricos.
|
||||
Puede buscar lo contrario de <code>\w</code> con <code>\W</code> Tenga en cuenta, el patrón opuesto utiliza una letra mayúscula. Este atajo es el mismo que <code>[^A-Za-z0-9_]</code> .
|
||||
<blockquote>let shortHand = /\W/;<br>let numbers = "42%";<br>let sentence = "Coding!";<br>numbers.match(shortHand); // Returns ["%"]<br>sentence.match(shortHand); // Returns ["!"]<br></blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Use la clase de caracteres abreviados <code>\W</code> para contar el número de caracteres no alfanuméricos en varias comillas y cadenas.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular debe utilizar la bandera global.
|
||||
testString: 'assert(nonAlphabetRegex.global, "Your regex should use the global flag.");'
|
||||
- text: Su expresión regular debe encontrar 6 caracteres no alfanuméricos en <code clase = "notranslate"> "Los cinco asistentes de boxeo saltan rápidamente".
|
||||
testString: 'assert("The five boxing wizards jump quickly.".match(nonAlphabetRegex).length == 6, "Your regex should find 6 non-alphanumeric characters in <code>"The five boxing wizards jump quickly."</code>.");'
|
||||
- text: Tu expresión regular debe usar el carácter de taquigrafía.
|
||||
testString: 'assert(/\\W/.test(nonAlphabetRegex.source), "Your regex should use the shorthand character to match characters which are non-alphanumeric.");'
|
||||
- text: Su expresión regular debe encontrar 8 caracteres no alfanuméricos en <code class = "notranslate"> "Empaque mi caja con cinco docenas de jarras de licor". </code>
|
||||
testString: 'assert("Pack my box with five dozen liquor jugs.".match(nonAlphabetRegex).length == 8, "Your regex should find 8 non-alphanumeric characters in <code>"Pack my box with five dozen liquor jugs."</code>");'
|
||||
- text: Tu expresión regular debe encontrar 6 caracteres no alfanuméricos en <code class = "notranslate"> "¡Qué rápido y zumbido de zebras!" </code>
|
||||
testString: 'assert("How vexingly quick daft zebras jump!".match(nonAlphabetRegex).length == 6, "Your regex should find 6 non-alphanumeric characters in <code>"How vexingly quick daft zebras jump!"</code>");'
|
||||
- text: Su expresión regular debe encontrar 12 caracteres no alfanuméricos en <code clase = "notranslate"> "123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ." </code>
|
||||
testString: 'assert("123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ.".match(nonAlphabetRegex).length == 12, "Your regex should find 12 non-alphanumeric characters in <code>"123 456 7890 ABC def GHI jkl MNO pqr STU vwx YZ."</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let quoteSample = "The five boxing wizards jump quickly.";
|
||||
let nonAlphabetRegex = /change/; // Change this line
|
||||
let result = quoteSample.match(nonAlphabetRegex).length;
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,60 @@
|
||||
---
|
||||
id: 587d7db5367417b2b2512b96
|
||||
title: Match Letters of the Alphabet
|
||||
localeTitle: Combina las letras del alfabeto
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Vio cómo puede usar los <code>character sets</code> para especificar un grupo de caracteres para hacer coincidir, pero eso es mucho para escribir cuando necesita hacer coincidir una gran variedad de caracteres (por ejemplo, todas las letras del alfabeto). Afortunadamente, hay una característica incorporada que hace que esto sea breve y simple.
|
||||
Dentro de un <code>character set</code> , puede definir un rango de caracteres para hacer coincidir usando un carácter de <code>hyphen</code> : <code>-</code> .
|
||||
Por ejemplo, para que coincida con las letras minúsculas <code>a</code> medio <code>e</code> que usaría <code>[ae]</code> .
|
||||
<blockquote>let catStr = "cat";<br>let batStr = "bat";<br>let matStr = "mat";<br>let bgRegex = /[a-e]at/;<br>catStr.match(bgRegex); // Returns ["cat"]<br>batStr.match(bgRegex); // Returns ["bat"]<br>matStr.match(bgRegex); // Returns null</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Coinciden con todas las letras en la cadena <code>quoteSample</code> .
|
||||
<strong>Nota</strong> <br> Asegúrese de hacer coincidir las <strong>letras</strong> mayúsculas y minúsculas <strong><strong>. <code>0</code></strong></strong> </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su regex <code>alphabetRegex</code> debe coincidir con 35 elementos.
|
||||
testString: 'assert(result.length == 35, "Your regex <code>alphabetRegex</code> should match 35 items.");'
|
||||
- text: Su regex <code>alphabetRegex</code> debe usar la bandera global.
|
||||
testString: 'assert(alphabetRegex.flags.match(/g/).length == 1, "Your regex <code>alphabetRegex</code> should use the global flag.");'
|
||||
- text: Su regex <code>alphabetRegex</code> debe usar la bandera que no distingue entre mayúsculas y minúsculas.
|
||||
testString: 'assert(alphabetRegex.flags.match(/i/).length == 1, "Your regex <code>alphabetRegex</code> should use the case insensitive flag.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let quoteSample = "The quick brown fox jumps over the lazy dog.";
|
||||
let alphabetRegex = /change/; // Change this line
|
||||
let result = alphabetRegex; // Change this line
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,61 @@
|
||||
---
|
||||
id: 587d7db3367417b2b2512b8f
|
||||
title: Match Literal Strings
|
||||
localeTitle: Unir cuerdas literales
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
En el último desafío, buscó la palabra <code>"Hello"</code> usando la expresión regular <code>/Hello/</code> . Esa expresión regular buscó una coincidencia literal de la cadena <code>"Hello"</code> . Aquí hay otro ejemplo que busca una coincidencia literal de la cadena <code>"Kevin"</code> :
|
||||
<blockquote>let testStr = "Hello, my name is Kevin.";<br>let testRegex = /Kevin/;<br>testRegex.test(testStr);<br>// Returns true</blockquote>
|
||||
Cualquier otra forma de <code>"Kevin"</code> no coincidirá. Por ejemplo, la expresión regular <code>/Kevin/</code> no coincidirá con <code>"kevin"</code> o <code>"KEVIN"</code> .
|
||||
<blockquote>let wrongRegex = /kevin/;<br>wrongRegex.test(testStr);<br>// Returns false</blockquote>
|
||||
Un desafío futuro mostrará cómo emparejar esas otras formas también.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Complete la expresión regular <code>waldoRegex</code> para encontrar <code>"Waldo"</code> en la cadena <code>waldoIsHiding</code> con una coincidencia literal.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Tu regex <code>waldoRegex</code> debería encontrar <code>"Waldo"</code>
|
||||
testString: 'assert(waldoRegex.test(waldoIsHiding), "Your regex <code>waldoRegex</code> should find <code>"Waldo"</code>");'
|
||||
- text: Su regex <code>waldoRegex</code> no debe buscar nada más.
|
||||
testString: 'assert(!waldoRegex.test("Somewhere is hiding in this text."), "Your regex <code>waldoRegex</code> should not search for anything else.");'
|
||||
- text: Debe realizar una coincidencia de cadena literal con su expresión regular.
|
||||
testString: 'assert(!/\/.*\/i/.test(code), "You should perform a literal string match with your regex.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let waldoIsHiding = "Somewhere Waldo is hiding in this text.";
|
||||
let waldoRegex = /search/; // Change this line
|
||||
let result = waldoRegex.test(waldoIsHiding);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,63 @@
|
||||
---
|
||||
id: 587d7db9367417b2b2512ba4
|
||||
title: Match Non-Whitespace Characters
|
||||
localeTitle: Combina caracteres que no sean espacios en blanco
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Aprendiste sobre la búsqueda de espacios en blanco usando <code>\s</code> , con una <code>s</code> minúscula. También puede buscar todo excepto espacios en blanco.
|
||||
Busque no espacios en blanco usando <code>\S</code> , que es un <code>s</code> mayúsculas. Este patrón no coincidirá con los espacios en blanco, el retorno de carro, la pestaña, el avance de página y los nuevos caracteres de línea. Puede pensar que es similar a la clase de caracteres <code>[^ \r\t\f\n\v]</code> .
|
||||
<blockquote>let whiteSpace = "Whitespace. Whitespace everywhere!"<br>let nonSpaceRegex = /\S/g;<br>whiteSpace.match(nonSpaceRegex).length; // Returns 32</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Cambie el regex <code>countNonWhiteSpace</code> para buscar múltiples caracteres que no sean espacios en blanco en una cadena.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular debe utilizar la bandera global.
|
||||
testString: 'assert(countNonWhiteSpace.global, "Your regex should use the global flag.");'
|
||||
- text: Tu expresión regular debe usar el carácter abreviado
|
||||
testString: 'assert(/\\S/.test(countNonWhiteSpace.source), "Your regex should use the shorthand character <code>\S/code> to match all non-whitespace characters.");'
|
||||
- text: Su expresión regular debe encontrar 35 espacios sin espacios en <code clase = "notranslate"> "Los hombres son de Marte y las mujeres son de Venus". </code>
|
||||
testString: 'assert("Men are from Mars and women are from Venus.".match(countNonWhiteSpace).length == 35, "Your regex should find 35 non-spaces in <code>"Men are from Mars and women are from Venus."</code>");'
|
||||
- text: 'Su expresión regular debe encontrar 23 espacios sin espacios en <code clase = "notranslate"> "Espacio: la frontera final". </code>'
|
||||
testString: 'assert("Space: the final frontier.".match(countNonWhiteSpace).length == 23, "Your regex should find 23 non-spaces in <code>"Space: the final frontier."</code>");'
|
||||
- text: Su expresión regular debe encontrar 21 espacios sin espacios en <code clase = "notranslate"> "MindYourPersonalSpace" </code>
|
||||
testString: 'assert("MindYourPersonalSpace".match(countNonWhiteSpace).length == 21, "Your regex should find 21 non-spaces in <code>"MindYourPersonalSpace"</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let sample = "Whitespace is important in separating words";
|
||||
let countNonWhiteSpace = /change/; // Change this line
|
||||
let result = sample.match(countNonWhiteSpace);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,60 @@
|
||||
---
|
||||
id: 587d7db5367417b2b2512b97
|
||||
title: Match Numbers and Letters of the Alphabet
|
||||
localeTitle: Coincidir números y letras del alfabeto
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
uso del guión ( <code>-</code> ) para hacer coincidir un rango de caracteres no se limita a las letras. También funciona para hacer coincidir un rango de números.
|
||||
Por ejemplo, <code>/[0-5]/</code> coincide con cualquier número entre <code>0</code> y <code>5</code> , incluidos <code>0</code> y <code>5</code> .
|
||||
Además, es posible combinar un rango de letras y números en un solo conjunto de caracteres.
|
||||
<blockquote>let jennyStr = "Jenny8675309";<br>let myRegex = /[a-z0-9]/ig;<br>// matches all letters and numbers in jennyStr<br>jennyStr.match(myRegex);</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Crear una sola expresión regular que coincide con una gama de cartas entre <code>h</code> y <code>s</code> , y una gama de números de entre <code>2</code> y <code>6</code> . Recuerde incluir las banderas apropiadas en la expresión regular.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Tu regex <code>myRegex</code> debe coincidir con 17 elementos.
|
||||
testString: 'assert(result.length == 17, "Your regex <code>myRegex</code> should match 17 items.");'
|
||||
- text: Su regex <code>myRegex</code> debe usar la bandera global.
|
||||
testString: 'assert(myRegex.flags.match(/g/).length == 1, "Your regex <code>myRegex</code> should use the global flag.");'
|
||||
- text: Su expresión regular <code>myRegex</code> debe usar la <code>myRegex</code> no distingue entre mayúsculas y minúsculas.
|
||||
testString: 'assert(myRegex.flags.match(/i/).length == 1, "Your regex <code>myRegex</code> should use the case insensitive flag.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let quoteSample = "Blueberry 3.141592653s are delicious.";
|
||||
let myRegex = /change/; // Change this line
|
||||
let result = myRegex; // Change this line
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,65 @@
|
||||
---
|
||||
id: 587d7db5367417b2b2512b95
|
||||
title: Match Single Character with Multiple Possibilities
|
||||
localeTitle: Coincidir con un solo personaje con múltiples posibilidades
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Aprendió cómo hacer coincidir patrones literales ( <code>/literal/</code> ) y caracteres comodín ( <code>/./</code> ). Esos son los extremos de las expresiones regulares, donde uno encuentra coincidencias exactas y el otro todo. Hay opciones que son un equilibrio entre los dos extremos.
|
||||
Puede buscar un patrón literal con cierta flexibilidad con las <code>character classes</code> . Las clases de caracteres le permiten definir un grupo de caracteres que desea hacer coincidiendo colocándolos entre corchetes cuadrados ( <code>[</code> y <code>]</code> ).
|
||||
Por ejemplo, desea hacer coincidir <code>"bag"</code> , <code>"big"</code> y <code>"bug"</code> pero no <code>"bog"</code> . Puede crear la expresión regular <code>/b[aiu]g/</code> para hacer esto. La <code>[aiu]</code> es la clase de caracteres que solo coincidirá con los caracteres <code>"a"</code> , <code>"i"</code> o <code>"u"</code> .
|
||||
<blockquote>let bigStr = "big";<br>let bagStr = "bag";<br>let bugStr = "bug";<br>let bogStr = "bog";<br>let bgRegex = /b[aiu]g/;<br>bigStr.match(bgRegex); // Returns ["big"]<br>bagStr.match(bgRegex); // Returns ["bag"]<br>bugStr.match(bgRegex); // Returns ["bug"]<br>bogStr.match(bgRegex); // Returns null</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Use una clase de caracteres con vocales ( <code>a</code> , <code>e</code> , <code>i</code> , <code>o</code> , <code>u</code> ) en su regex <code>vowelRegex</code> para encontrar todas las vocales en la cadena <code>quoteSample</code> .
|
||||
<strong>Nota</strong> <br> Asegúrese de hacer coincidir las vocales mayúsculas y minúsculas.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Debes encontrar las 25 vocales.
|
||||
testString: 'assert(result.length == 25, "You should find all 25 vowels.");'
|
||||
- text: Su regex <code class = "notranslate"> vowelRegex </code> debe usar una clase de caracteres.
|
||||
testString: 'assert(/\[.*\]/.test(vowelRegex.source), "Your regex <code>vowelRegex</code> should use a character class.");'
|
||||
- text: Su regex <code class = "notranslate"> vowelRegex </code> debe usar la bandera global.
|
||||
testString: 'assert(vowelRegex.flags.match(/g/).length == 1, "Your regex <code>vowelRegex</code> should use the global flag.");'
|
||||
- text: Su regex <code class = "notranslate"> vowelRegex </code> debe usar la marca que no distingue entre mayúsculas y minúsculas.
|
||||
testString: 'assert(vowelRegex.flags.match(/i/).length == 1, "Your regex <code>vowelRegex</code> should use the case insensitive flag.");'
|
||||
- text: Su expresión regular no debe coincidir con ninguna consonante.
|
||||
testString: 'assert(!/[b-df-hj-np-tv-z]/gi.test(result.join()), "Your regex should not match any consonants.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let quoteSample = "Beware of bugs in the above code; I have only proved it correct, not tried it.";
|
||||
let vowelRegex = /change/; // Change this line
|
||||
let result = vowelRegex; // Change this line
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,59 @@
|
||||
---
|
||||
id: 587d7db6367417b2b2512b98
|
||||
title: Match Single Characters Not Specified
|
||||
localeTitle: Coincidir con caracteres individuales no especificados
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Hasta ahora, ha creado un conjunto de caracteres que desea hacer coincidir, pero también puede crear un conjunto de caracteres que no desea que coincida. Estos tipos de conjuntos de caracteres se denominan <code>negated character sets</code> .
|
||||
Para crear un <code>negated character set</code> , coloque un carácter de <code>caret</code> ( <code>^</code> ) después del corchete de apertura y antes de los caracteres que no desea que coincidan.
|
||||
Por ejemplo, <code>/[^aeiou]/gi</code> coincide con todos los caracteres que no son una vocal. Tenga en cuenta que a los personajes les gusta <code>.</code> , <code>!</code> , <code>[</code> , <code>@</code> , <code>/</code> y el espacio en blanco coinciden: el conjunto de caracteres de la vocal negada solo excluye los caracteres de la vocal.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Cree una expresión regular única que coincida con todos los caracteres que no sean un número o una vocal. Recuerde incluir las banderas apropiadas en la expresión regular.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Tu regex <code>myRegex</code> debe coincidir con 9 elementos.
|
||||
testString: 'assert(result.length == 9, "Your regex <code>myRegex</code> should match 9 items.");'
|
||||
- text: Su regex <code>myRegex</code> debe usar la bandera global.
|
||||
testString: 'assert(myRegex.flags.match(/g/).length == 1, "Your regex <code>myRegex</code> should use the global flag.");'
|
||||
- text: Su expresión regular <code>myRegex</code> debe usar la <code>myRegex</code> no distingue entre mayúsculas y minúsculas.
|
||||
testString: 'assert(myRegex.flags.match(/i/).length == 1, "Your regex <code>myRegex</code> should use the case insensitive flag.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let quoteSample = "3 blind mice.";
|
||||
let myRegex = /change/; // Change this line
|
||||
let result = myRegex; // Change this line
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,63 @@
|
||||
---
|
||||
id: 587d7db8367417b2b2512ba3
|
||||
title: Match Whitespace
|
||||
localeTitle: Emparejar espacios en blanco
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Los desafíos hasta ahora han cubierto las letras correspondientes del alfabeto y los números. También puede hacer coincidir los espacios en blanco o espacios entre letras.
|
||||
Puede buscar espacios en blanco usando <code>\s</code> , que es un <code>s</code> minúscula. Este patrón no solo coincide con el espacio en blanco, sino también con el retorno de carro, la pestaña, el avance de página y los nuevos caracteres de línea. Puede pensar que es similar a la clase de caracteres <code>[ \r\t\f\n\v]</code> .
|
||||
<blockquote>let whiteSpace = "Whitespace. Whitespace everywhere!"<br>let spaceRegex = /\s/g;<br>whiteSpace.match(spaceRegex);<br>// Returns [" ", " "]<br></blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Cambie el regex <code>countWhiteSpace</code> para buscar múltiples caracteres de espacio en blanco en una cadena.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular debe utilizar la bandera global.
|
||||
testString: 'assert(countWhiteSpace.global, "Your regex should use the global flag.");'
|
||||
- text: Tu expresión regular debe usar el carácter abreviado
|
||||
testString: 'assert(/\\s/.test(countWhiteSpace.source), "Your regex should use the shorthand character <code>\s</code> to match all whitespace characters.");'
|
||||
- text: Su expresión regular debe encontrar ocho espacios en <code clase = "notranslate"> "Los hombres son de Marte y las mujeres son de Venus". </code>
|
||||
testString: 'assert("Men are from Mars and women are from Venus.".match(countWhiteSpace).length == 8, "Your regex should find eight spaces in <code>"Men are from Mars and women are from Venus."</code>");'
|
||||
- text: 'Tu expresión regular debe encontrar tres espacios en <code clase = "notranslate"> "Espacio: la frontera final." </code>'
|
||||
testString: 'assert("Space: the final frontier.".match(countWhiteSpace).length == 3, "Your regex should find three spaces in <code>"Space: the final frontier."</code>");'
|
||||
- text: Su expresión regular no debe encontrar espacios en <code clase = "notranslate"> "MindYourPersonalSpace" </code>
|
||||
testString: 'assert("MindYourPersonalSpace".match(countWhiteSpace) == null, "Your regex should find no spaces in <code>"MindYourPersonalSpace"</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let sample = "Whitespace is important in separating words";
|
||||
let countWhiteSpace = /change/; // Change this line
|
||||
let result = sample.match(countWhiteSpace);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,76 @@
|
||||
---
|
||||
id: 587d7dba367417b2b2512ba9
|
||||
title: Positive and Negative Lookahead
|
||||
localeTitle: Lookahead positivo y negativo
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
<code>Lookaheads</code> son patrones que le dicen a JavaScript que mire hacia adelante en su cadena para buscar patrones más adelante. Esto puede ser útil cuando desea buscar múltiples patrones sobre la misma cadena.
|
||||
Hay dos tipos de <code>lookaheads</code> : <code>positive lookahead</code> y <code>negative lookahead</code> .
|
||||
Un <code>positive lookahead</code> mirará para asegurarse de que el elemento en el patrón de búsqueda esté allí, pero en realidad no lo coincidirá. Un lookahead positivo se usa como <code>(?=...)</code> donde <code>...</code> es la parte requerida que no coincide.
|
||||
Por otro lado, un <code>negative lookahead</code> se verá para asegurarse de que el elemento en el patrón de búsqueda no esté allí. Un lookahead negativo se usa como <code>(?!...)</code> donde el <code>...</code> es el patrón que no desea que esté allí. El resto del patrón se devuelve si la parte de búsqueda anticipada negativa no está presente.
|
||||
Lookaheads son un poco confusos, pero algunos ejemplos ayudarán.
|
||||
<blockquote>let quit = "qu";<br>let noquit = "qt";<br>let quRegex= /q(?=u)/;<br>let qRegex = /q(?!u)/;<br>quit.match(quRegex); // Returns ["q"]<br>noquit.match(qRegex); // Returns ["q"]</blockquote>
|
||||
Un uso más práctico de <code>lookaheads</code> es marcar dos o más patrones en una cadena. Aquí hay un verificador de contraseña (ingenuamente) simple que busca entre 3 y 6 caracteres y al menos un número:
|
||||
<blockquote>let password = "abc123";<br>let checkPass = /(?=\w{3,6})(?=\D*\d)/;<br>checkPass.test(password); // Returns true</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Use <code>lookaheads</code> en el <code>pwRegex</code> para hacer coincidir las contraseñas que tienen más de 5 caracteres y tienen dos dígitos consecutivos.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular debe utilizar dos <code>lookaheads</code> positivos.
|
||||
testString: 'assert(pwRegex.source.match(/\(\?=.*?\)\(\?=.*?\)/) !== null, "Your regex should use two positive <code>lookaheads</code>.");'
|
||||
- text: Tu expresión regular no debe coincidir con <code>"astronaut"</code>
|
||||
testString: 'assert(!pwRegex.test("astronaut"), "Your regex should not match <code>"astronaut"</code>");'
|
||||
- text: Su expresión regular no debe coincidir con <code>"airplanes"</code>
|
||||
testString: 'assert(!pwRegex.test("airplanes"), "Your regex should not match <code>"airplanes"</code>");'
|
||||
- text: Tu expresión regular no debe coincidir con <code>"banan1"</code>
|
||||
testString: 'assert(!pwRegex.test("banan1"), "Your regex should not match <code>"banan1"</code>");'
|
||||
- text: Tu expresión regular debe coincidir con <code>"bana12"</code>
|
||||
testString: 'assert(pwRegex.test("bana12"), "Your regex should match <code>"bana12"</code>");'
|
||||
- text: Tu expresión regular debe coincidir con <code>"abc123"</code>
|
||||
testString: 'assert(pwRegex.test("abc123"), "Your regex should match <code>"abc123"</code>");'
|
||||
- text: Su expresión regular no debe coincidir con <code>"123"</code>
|
||||
testString: 'assert(!pwRegex.test("123"), "Your regex should not match <code>"123"</code>");'
|
||||
- text: Su expresión regular no debe coincidir con <code>"1234"</code>
|
||||
testString: 'assert(!pwRegex.test("1234"), "Your regex should not match <code>"1234"</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let sampleWord = "astronaut";
|
||||
let pwRegex = /change/; // Change this line
|
||||
let result = pwRegex.test(sampleWord);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
|
||||
```js
|
||||
var pwRegex = /(?=\w{5})(?=\D*\d{2})/;
|
||||
```
|
||||
|
||||
</section>
|
@@ -0,0 +1,58 @@
|
||||
---
|
||||
id: 587d7dbb367417b2b2512bac
|
||||
title: Remove Whitespace from Start and End
|
||||
localeTitle: Eliminar espacios en blanco de inicio y fin
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
A veces, los caracteres de espacios en blanco alrededor de las cadenas no son deseados pero están ahí. El procesamiento típico de las cadenas es eliminar el espacio en blanco al principio y al final.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Escriba una expresión regular y use los métodos de cadena apropiados para eliminar los espacios en blanco al principio y al final de las cadenas.
|
||||
<strong>Nota</strong> <br> El método <code>.trim()</code> funcionaría aquí, pero necesitarás completar este desafío usando expresiones regulares.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: El <code>result</code> debería ser igual a <code>"Hello, World!"</code> '
|
||||
testString: 'assert(result == "Hello, World!", "<code>result</code> should equal to <code>"Hello, World!"</code>");'
|
||||
- text: No debes usar el método <code>.trim()</code> .
|
||||
testString: 'assert(!code.match(/\.trim\(.*?\)/), "You should not use the <code>.trim()</code> method.");'
|
||||
- text: La variable de <code>result</code> no debe ser igual a una cadena.
|
||||
testString: 'assert(!code.match(/result\s*=\s*".*?"/), "The <code>result</code> variable should not be set equal to a string.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let hello = " Hello, World! ";
|
||||
let wsRegex = /change/; // Change this line
|
||||
let result = hello; // Change this line
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,67 @@
|
||||
---
|
||||
id: 587d7db8367417b2b2512ba2
|
||||
title: Restrict Possible Usernames
|
||||
localeTitle: Restringir posibles nombres de usuario
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
nombres de usuario se utilizan en todas partes en Internet. Son los que dan a los usuarios una identidad única en sus sitios favoritos.
|
||||
Es necesario comprobar todos los nombres de usuario en una base de datos. Aquí hay algunas reglas simples que los usuarios deben seguir al crear su nombre de usuario.
|
||||
1) Los únicos números en el nombre de usuario deben estar al final. Puede haber cero o más de ellos al final.
|
||||
2) Las letras de los nombres de usuario pueden estar en minúsculas y mayúsculas.
|
||||
3) Los nombres de usuario deben tener al menos dos caracteres. Un nombre de usuario de dos letras solo puede usar caracteres de letras del alfabeto.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Cambie el regex <code>userCheck</code> para que se ajuste a las restricciones enumeradas anteriormente.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Tu expresión regular debe coincidir con <code>JACK</code>
|
||||
testString: 'assert(userCheck.test("JACK"), "Your regex should match <code>JACK</code>");'
|
||||
- text: Tu expresión regular no debe coincidir con <code>J</code>
|
||||
testString: 'assert(!userCheck.test("J"), "Your regex should not match <code>J</code>");'
|
||||
- text: Tu expresión regular debe coincidir con <code>Oceans11</code>
|
||||
testString: 'assert(userCheck.test("Oceans11"), "Your regex should match <code>Oceans11</code>");'
|
||||
- text: Tu expresión regular debe coincidir con <code>RegexGuru</code>
|
||||
testString: 'assert(userCheck.test("RegexGuru"), "Your regex should match <code>RegexGuru</code>");'
|
||||
- text: Su expresión regular no debe coincidir con <code>007</code>
|
||||
testString: 'assert(!userCheck.test("007"), "Your regex should not match <code>007</code>");'
|
||||
- text: Tu expresión regular no debe coincidir con <code>9</code>
|
||||
testString: 'assert(!userCheck.test("9"), "Your regex should not match <code>9</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let username = "JackOfAllTrades";
|
||||
let userCheck = /change/; // Change this line
|
||||
let result = userCheck.test(username);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,76 @@
|
||||
---
|
||||
id: 587d7dbb367417b2b2512baa
|
||||
title: Reuse Patterns Using Capture Groups
|
||||
localeTitle: Reutilizar patrones usando grupos de captura
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Algunos patrones que busca ocurrirán varias veces en una cadena. Es un desperdicio repetir manualmente la expresión regular. Hay una mejor manera de especificar cuándo tiene varias subcadenas de repetición en su cadena.
|
||||
Puede buscar subcadenas repetidas usando <code>capture groups</code> . Los paréntesis, <code>(</code> y <code>)</code> , se utilizan para encontrar subcadenas repetidas. Pones la expresión regular del patrón que se repetirá entre paréntesis.
|
||||
Para especificar dónde aparecerá esa cadena de repetición, use una barra diagonal inversa ( <code>\</code> ) y luego un número. Este número comienza en 1 y aumenta con cada grupo de captura adicional que use. Un ejemplo sería <code>\1</code> para que coincida con el primer grupo.
|
||||
El siguiente ejemplo coincide con cualquier palabra que aparezca dos veces separadas por un espacio:
|
||||
<blockquote>let repeatStr = "regex regex";<br>let repeatRegex = /(\w+)\s\1/;<br>repeatRegex.test(repeatStr); // Returns true<br>repeatStr.match(repeatRegex); // Returns ["regex regex", "regex"]</blockquote>
|
||||
uso del método <code>.match()</code> en una cadena devolverá una matriz con la cadena que coincide, junto con su grupo de captura.
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Use los <code>capture groups</code> en <code>reRegex</code> para hacer coincidir los números que se repiten solo tres veces en una cadena, cada uno separado por un espacio.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular debe usar la clase de caracteres abreviados para los dígitos.
|
||||
testString: 'assert(reRegex.source.match(/\\d/), "Your regex should use the shorthand character class for digits.");'
|
||||
- text: Su expresión regular debe reutilizar el grupo de captura dos veces.
|
||||
testString: 'assert(reRegex.source.match(/\\\d/g).length === 2, "Your regex should reuse the capture group twice.");'
|
||||
- text: Su expresión regular debe tener dos espacios que separan los tres números.
|
||||
testString: 'assert(reRegex.source.match(/\\s/g).length === 2, "Your regex should have two spaces separating the three numbers.");'
|
||||
- text: Su expresión regular debe coincidir con <code class = "notranslate"> "42 42 42" </code>.
|
||||
testString: 'assert(reRegex.test("42 42 42"), "Your regex should match <code>"42 42 42"</code>.");'
|
||||
- text: Su expresión regular debe coincidir con <code class = "notranslate"> "100 100 100" </code>.
|
||||
testString: 'assert(reRegex.test("100 100 100"), "Your regex should match <code>"100 100 100"</code>.");'
|
||||
- text: Su expresión regular no debe coincidir con <code clase = "notranslate"> "42 42 42 42" </code>.
|
||||
testString: 'assert.equal(("42 42 42 42").match(reRegex.source), null, "Your regex should not match <code>"42 42 42 42"</code>.");'
|
||||
- text: Su expresión regular no debe coincidir con <code clase = "notranslate"> "42 42" </code>.
|
||||
testString: 'assert.equal(("42 42").match(reRegex.source), null, "Your regex should not match <code>"42 42"</code>.");'
|
||||
- text: Su expresión regular no debe coincidir con <code clase = "notranslate"> "101 102 103" </code>.
|
||||
testString: 'assert(!reRegex.test("101 102 103"), "Your regex should not match <code>"101 102 103"</code>.");'
|
||||
- text: Su expresión regular no debe coincidir con <code clase = "notranslate"> "1 2 3" </code>.
|
||||
testString: 'assert(!reRegex.test("1 2 3"), "Your regex should not match <code>"1 2 3"</code>.");'
|
||||
- text: Su expresión regular debe coincidir con <code class = "notranslate"> "10 10 10" </code>.
|
||||
testString: 'assert(reRegex.test("10 10 10"), "Your regex should match <code>"10 10 10"</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let repeatNum = "42 42 42";
|
||||
let reRegex = /change/; // Change this line
|
||||
let result = reRegex.test(repeatNum);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,66 @@
|
||||
---
|
||||
id: 587d7db9367417b2b2512ba7
|
||||
title: Specify Exact Number of Matches
|
||||
localeTitle: Especifique el número exacto de coincidencias
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Puede especificar el número inferior y superior de patrones con <code>quantity specifiers</code> utilizando llaves. A veces solo quieres un número específico de coincidencias.
|
||||
Para especificar un cierto número de patrones, solo tiene ese número entre las llaves.
|
||||
Por ejemplo, para hacer coincidir solo la palabra <code>"hah"</code> con la letra <code>a</code> <code>3</code> veces, su expresión regular sería <code>/ha{3}h/</code> .
|
||||
<blockquote>let A4 = "haaaah";<br>let A3 = "haaah";<br>let A100 = "h" + "a".repeat(100) + "h";<br>let multipleHA = /ha{3}h/;<br>multipleHA.test(A4); // Returns false<br>multipleHA.test(A3); // Returns true<br>multipleHA.test(A100); // Returns false</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Cambie el regex <code>timRegex</code> para que coincida con la palabra <code>"Timber"</code> solo cuando tenga cuatro letras <code>m</code> .
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular debe utilizar llaves.
|
||||
testString: 'assert(timRegex.source.match(/{.*?}/).length > 0, "Your regex should use curly brackets.");'
|
||||
- text: Su expresión regular no debe coincidir con <code class = "notranslate"> "Timber" </code>
|
||||
testString: 'assert(!timRegex.test("Timber"), "Your regex should not match <code>"Timber"</code>");'
|
||||
- text: Su expresión regular no debe coincidir con <code class = "notranslate"> "Timmber" </code>
|
||||
testString: 'assert(!timRegex.test("Timmber"), "Your regex should not match <code>"Timmber"</code>");'
|
||||
- text: Su expresión regular no debe coincidir con <code class = "notranslate"> "Timmmber" </code>
|
||||
testString: 'assert(!timRegex.test("Timmmber"), "Your regex should not match <code>"Timmmber"</code>");'
|
||||
- text: Su expresión regular debe coincidir con <code class = "notranslate"> "Timmmmber" </code>
|
||||
testString: 'assert(timRegex.test("Timmmmber"), "Your regex should match <code>"Timmmmber"</code>");'
|
||||
- text: Su expresión regular no debe coincidir con <code class = "notranslate"> "Timber" </code> con 30 <code class = "notranslate"> m </code> en ella.
|
||||
testString: 'assert(!timRegex.test("Ti" + "m".repeat(30) + "ber"), "Your regex should not match <code>"Timber"</code> with 30 <code>m</code>\"s in it.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let timStr = "Timmmmber";
|
||||
let timRegex = /change/; // Change this line
|
||||
let result = timRegex.test(timStr);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,68 @@
|
||||
---
|
||||
id: 587d7db9367417b2b2512ba6
|
||||
title: Specify Only the Lower Number of Matches
|
||||
localeTitle: Especifique solo el número inferior de coincidencias
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Puede especificar el número inferior y superior de patrones con <code>quantity specifiers</code> utilizando llaves. A veces solo desea especificar el número más bajo de patrones sin límite superior.
|
||||
Para especificar solo el número más bajo de patrones, mantenga el primer número seguido de una coma.
|
||||
Por ejemplo, para hacer coincidir solo la cadena <code>"hah"</code> con la letra <code>a</code> aparece al menos <code>3</code> veces, su expresión regular sería <code>/ha{3,}h/</code> .
|
||||
<blockquote>let A4 = "haaaah";<br>let A2 = "haah";<br>let A100 = "h" + "a".repeat(100) + "h";<br>let multipleA = /ha{3,}h/;<br>multipleA.test(A4); // Returns true<br>multipleA.test(A2); // Returns false<br>multipleA.test(A100); // Returns true</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Cambie el regex <code>haRegex</code> para que coincida con la palabra <code>"Hazzah"</code> solo cuando tenga cuatro o más letras <code>z</code> 's.
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular debe utilizar llaves.
|
||||
testString: 'assert(haRegex.source.match(/{.*?}/).length > 0, "Your regex should use curly brackets.");'
|
||||
- text: Su expresión regular no debe coincidir con <code clase = "notranslate"> "Hazzah" </code>
|
||||
testString: 'assert(!haRegex.test("Hazzah"), "Your regex should not match <code>"Hazzah"</code>");'
|
||||
- text: Su expresión regular no debe coincidir con <code clase = "notranslate"> "Hazzzah" </code>
|
||||
testString: 'assert(!haRegex.test("Hazzzah"), "Your regex should not match <code>"Hazzzah"</code>");'
|
||||
- text: Su expresión regular debe coincidir con <code clase = "notranslate"> "Hazzzzah" </code>
|
||||
testString: 'assert(haRegex.test("Hazzzzah"), "Your regex should match <code>"Hazzzzah"</code>");'
|
||||
- text: Su expresión regular debe coincidir con <code class = "notranslate"> "Hazzzzzah" </code>
|
||||
testString: 'assert(haRegex.test("Hazzzzzah"), "Your regex should match <code>"Hazzzzzah"</code>");'
|
||||
- text: Su expresión regular debe coincidir con <code class = "notranslate"> "Hazzzzzzah" </code>
|
||||
testString: 'assert(haRegex.test("Hazzzzzzah"), "Your regex should match <code>"Hazzzzzzah"</code>");'
|
||||
- text: Su expresión regular debe coincidir con <code class = "notranslate"> "Hazzah" </code> con 30 <code class = "notranslate"> z </code> \ 's en ella.
|
||||
testString: 'assert(haRegex.test("Ha" + "z".repeat(30) + "ah"), "Your regex should match <code>"Hazzah"</code> with 30 <code>z</code>\"s in it.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let haStr = "Hazzzzah";
|
||||
let haRegex = /change/; // Change this line
|
||||
let result = haRegex.test(haStr);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,68 @@
|
||||
---
|
||||
id: 587d7db9367417b2b2512ba5
|
||||
title: Specify Upper and Lower Number of Matches
|
||||
localeTitle: Especifique el número superior e inferior de coincidencias
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Recuerde que usa el signo más <code>+</code> para buscar uno o más caracteres y el asterisco <code>*</code> para buscar cero o más caracteres. Estos son convenientes, pero a veces usted quiere hacer coincidir un cierto rango de patrones.
|
||||
Puede especificar el número inferior y superior de patrones con <code>quantity specifiers</code> . Los especificadores de cantidad se utilizan con llaves ( <code>{</code> y <code>}</code> ). Pones dos números entre las llaves: para el número inferior y superior de patrones.
|
||||
Por ejemplo, para hacer coincidir solo la letra <code>a</code> aparece entre <code>3</code> y <code>5</code> veces en la cadena <code>"ah"</code> , su expresión regular sería <code>/a{3,5}h/</code> .
|
||||
<blockquote>let A4 = "aaaah";<br>let A2 = "aah";<br>let multipleA = /a{3,5}h/;<br>multipleA.test(A4); // Returns true<br>multipleA.test(A2); // Returns false</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Cambie el regex <code>ohRegex</code> para que coincida solo con <code>3</code> a <code>6</code> letras <code>h</code> en la palabra <code>"Oh no"</code> .
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Su expresión regular debe utilizar llaves.
|
||||
testString: 'assert(ohRegex.source.match(/{.*?}/).length > 0, "Your regex should use curly brackets.");'
|
||||
- text: Su expresión regular no debe coincidir con <code clase = "notranslate"> "Ohh no" </code>
|
||||
testString: 'assert(!ohRegex.test("Ohh no"), "Your regex should not match <code>"Ohh no"</code>");'
|
||||
- text: Su expresión regular debe coincidir con <code clase = "notranslate"> "Ohhh no" </code>
|
||||
testString: 'assert(ohRegex.test("Ohhh no"), "Your regex should match <code>"Ohhh no"</code>");'
|
||||
- text: Su expresión regular debe coincidir con <code clase = "notranslate"> "Ohhhh no" </code>
|
||||
testString: 'assert(ohRegex.test("Ohhhh no"), "Your regex should match <code>"Ohhhh no"</code>");'
|
||||
- text: Su expresión regular debe coincidir con <code clase = "notranslate"> "Ohhhhh no" </code>
|
||||
testString: 'assert(ohRegex.test("Ohhhhh no"), "Your regex should match <code>"Ohhhhh no"</code>");'
|
||||
- text: Su expresión regular debe coincidir con <code clase = "notranslate"> "Ohhhhhh no" </code>
|
||||
testString: 'assert(ohRegex.test("Ohhhhhh no"), "Your regex should match <code>"Ohhhhhh no"</code>");'
|
||||
- text: Su expresión regular no debe coincidir con <code clase = "notranslate"> "Ohhhhhhh no" </code>
|
||||
testString: 'assert(!ohRegex.test("Ohhhhhhh no"), "Your regex should not match <code>"Ohhhhhhh no"</code>");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let ohStr = "Ohhh no";
|
||||
let ohRegex = /change/; // Change this line
|
||||
let result = ohRegex.test(ohStr);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,63 @@
|
||||
---
|
||||
id: 587d7dbb367417b2b2512bab
|
||||
title: Use Capture Groups to Search and Replace
|
||||
localeTitle: Utilice los grupos de captura para buscar y reemplazar
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
búsqueda es útil. Sin embargo, puede hacer que la búsqueda sea aún más poderosa cuando también cambia (o reemplaza) el texto que coincide.
|
||||
Puede buscar y reemplazar texto en una cadena usando <code>.replace()</code> en una cadena. Las entradas para <code>.replace()</code> son primero el patrón de <code>.replace()</code> regulares que desea buscar. El segundo parámetro es la cadena para reemplazar la coincidencia o una función para hacer algo.
|
||||
<blockquote>let wrongText = "The sky is silver.";<br>let silverRegex = /silver/;<br>wrongText.replace(silverRegex, "blue");<br>// Returns "The sky is blue."</blockquote>
|
||||
También puede acceder a grupos de captura en la cadena de reemplazo con signos de dólar ( <code>$</code> ).
|
||||
<blockquote>"Code Camp".replace(/(\w+)\s(\w+)/, '$2
|
||||
');<br>// Returns "Camp Code"</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Escriba una expresión regular para que busque la cadena <code>"good"</code> . Luego actualice la variable <code>replaceText</code> para reemplazar <code>"good"</code> con <code>"okey-dokey"</code> .
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Debes usar <code>.replace()</code> para buscar y reemplazar.
|
||||
testString: 'assert(code.match(/\.replace\(.*\)/), "You should use <code>.replace()</code> to search and replace.");'
|
||||
- text: Tu expresión regular debería cambiar <code>"This sandwich is good."</code> a <code>"This sandwich is okey-dokey."</code>
|
||||
testString: 'assert(result == "This sandwich is okey-dokey." && replaceText === "okey-dokey", "Your regex should change <code>"This sandwich is good."</code> to <code>"This sandwich is okey-dokey."</code>");'
|
||||
- text: No debes cambiar la última línea.
|
||||
testString: 'assert(code.match(/result\s*=\s*huhText\.replace\(.*?\)/), "You should not change the last line.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let huhText = "This sandwich is good.";
|
||||
let fixRegex = /change/; // Change this line
|
||||
let replaceText = ""; // Change this line
|
||||
let result = huhText.replace(fixRegex, replaceText);
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@@ -0,0 +1,58 @@
|
||||
---
|
||||
id: 587d7db3367417b2b2512b8e
|
||||
title: Using the Test Method
|
||||
localeTitle: Usando el Método de Prueba
|
||||
challengeType: 1
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id='description'>
|
||||
Las expresiones regulares se usan en lenguajes de programación para hacer coincidir partes de cadenas. Creas patrones para ayudarte a hacer ese emparejamiento.
|
||||
Si desea buscar la palabra <code>"the"</code> en la cadena <code>"The dog chased the cat"</code> , puede usar la siguiente expresión regular: <code>/the/</code> . Observe que las comillas no son necesarias dentro de la expresión regular.
|
||||
JavaScript tiene múltiples formas de usar expresiones regulares. Una forma de probar una expresión regular es mediante el método <code>.test()</code> . El método <code>.test()</code> toma la expresión regular, la aplica a una cadena (que se coloca entre paréntesis) y devuelve <code>true</code> o <code>false</code> si su patrón encuentra algo o no.
|
||||
<blockquote>let testStr = "freeCodeCamp";<br>let testRegex = /Code/;<br>testRegex.test(testStr);<br>// Returns true</blockquote>
|
||||
</section>
|
||||
|
||||
## Instructions
|
||||
<section id='instructions'>
|
||||
Aplique el regex <code>myRegex</code> en la cadena <code>myString</code> usando el método <code>.test()</code> .
|
||||
</section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Debe usar <code>.test()</code> para probar la expresión regular.
|
||||
testString: 'assert(code.match(/myRegex.test\(\s*myString\s*\)/), "You should use <code>.test()</code> to test the regex.");'
|
||||
- text: Su resultado debe devolver <code>true</code> .
|
||||
testString: 'assert(result === true, "Your result should return <code>true</code>.");'
|
||||
|
||||
```
|
||||
|
||||
</section>
|
||||
|
||||
## Challenge Seed
|
||||
<section id='challengeSeed'>
|
||||
|
||||
<div id='js-seed'>
|
||||
|
||||
```js
|
||||
let myString = "Hello, World!";
|
||||
let myRegex = /Hello/;
|
||||
let result = myRegex; // Change this line
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</section>
|
||||
|
||||
## Solution
|
||||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
```
|
||||
</section>
|
Reference in New Issue
Block a user