Add languages Russian, Arabic, Chinese, Portuguese (#18305)
This commit is contained in:
committed by
mrugesh mohapatra
parent
09d3eca712
commit
2ca3a2093f
@ -0,0 +1,57 @@
|
||||
---
|
||||
id: 587d7dba367417b2b2512ba8
|
||||
title: Check for All or None
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Verificar tudo ou nada
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Às vezes, os padrões que você deseja pesquisar podem ter partes dele que podem ou não existir. No entanto, pode ser importante verificar para eles, no entanto. Você pode especificar a possível existência de um elemento com um ponto de interrogação <code>?</code> . Isso verifica zero ou um dos elementos anteriores. Você pode pensar neste símbolo dizendo que o elemento anterior é opcional. Por exemplo, existem pequenas diferenças no inglês americano e britânico e você pode usar o ponto de interrogação para combinar com as duas grafias. <blockquote> deixe americano = "cor"; <br> deixe british = "cor"; <br> deixe rainbowRegex = / colou? r /; <br> rainbowRegex.test (americano); // Retorna true <br> rainbowRegex.test (britânico); // Retorna true </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere o regex <code>favRegex</code> para coincidir com o inglês americano (favorito) e o inglês britânico (favorito) versão da palavra. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve usar o símbolo opcional <code>?</code> .
|
||||
testString: 'assert(favRegex.source.match(/\?/).length > 0, "Your regex should use the optional symbol, <code>?</code>.");'
|
||||
- text: Seu regex deve coincidir com <code>"favorite"</code>
|
||||
testString: 'assert(favRegex.test("favorite"), "Your regex should match <code>"favorite"</code>");'
|
||||
- text: Seu regex deve coincidir com <code>"favourite"</code>
|
||||
testString: 'assert(favRegex.test("favourite"), "Your regex should match <code>"favourite"</code>");'
|
||||
- text: Seu regex não deve corresponder a <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,55 @@
|
||||
---
|
||||
id: 587d7db4367417b2b2512b92
|
||||
title: Extract Matches
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Extrair correspondências
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Até agora, você só verifica se um padrão existe ou não em uma string. Você também pode extrair as correspondências reais encontradas com o método <code>.match()</code> . Para usar o método <code>.match()</code> , aplique o método em uma string e passe o regex dentro dos parênteses. Aqui está um exemplo: <blockquote> "Olá, mundo!". Match (/ Hello /); <br> // Retorna ["Olá"] <br> vamos ourStr = "Expressões regulares"; <br> vamos ourRegex = / expressões /; <br> ourStr.match (ourRegex); <br> // Retorna ["expressões"] </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Aplique o método <code>.match()</code> para extrair a <code>coding</code> palavras. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: O <code>result</code> deve ter a palavra <code>coding</code>
|
||||
testString: 'assert(result.join() === "coding", "The <code>result</code> should have the word <code>coding</code>");'
|
||||
- text: Seu regex <code>codingRegex</code> deve procurar por <code>coding</code>
|
||||
testString: 'assert(codingRegex.source === "coding", "Your regex <code>codingRegex</code> should search for <code>coding</code>");'
|
||||
- text: Você deve usar o 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,51 @@
|
||||
---
|
||||
id: 587d7db6367417b2b2512b9b
|
||||
title: Find Characters with Lazy Matching
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Encontrar personagens com correspondência preguiçosa
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Em expressões regulares, uma correspondência <code>greedy</code> localiza a parte mais longa possível de uma sequência que se ajusta ao padrão de expressão regular e a retorna como uma correspondência. A alternativa é chamada de <code>lazy</code> match, que encontra a menor parte possível da string que satisfaz o padrão de expressão regular. Você pode aplicar o regex <code>/t[az]*i/</code> à string <code>"titanic"</code> . Este regex é basicamente um padrão que começa com <code>t</code> , termina com <code>i</code> e tem algumas letras no meio. Expressões regulares são por padrão <code>greedy</code> , então a correspondência retornaria <code>["titani"]</code> . Ele encontra a maior sub-string possível para ajustar o padrão. No entanto, você pode usar o <code>?</code> personagem para alterá-lo para correspondência <code>lazy</code> . <code>"titanic"</code> combinou com o regex ajustado de <code>/t[az]*?i/</code> returns <code>["ti"]</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Corrija o regex <code>/<.*>/</code> para retornar a tag HTML <code><h1></code> e não o texto <code>"<h1>Winter is coming</h1>"</code> . Lembre-se do curinga <code>.</code> em uma expressão regular corresponde a qualquer caractere. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: A variável de <code>result</code> deve ser uma matriz com <code><h1></code> nela
|
||||
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,57 @@
|
||||
---
|
||||
id: 587d7db4367417b2b2512b93
|
||||
title: Find More Than the First Match
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Encontre mais do que o primeiro jogo
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Até agora, você só conseguiu extrair ou pesquisar um padrão uma vez. <blockquote> deixe testStr = "Repetir, Repetir, Repetir"; <br> vamos ourRegex = / Repeat /; <br> testStr.match (ourRegex); <br> // Retorna ["Repetir"] </blockquote> Para pesquisar ou extrair um padrão mais de uma vez, você pode usar o sinalizador <code>g</code> . <blockquote> vamos repeatRegex = / Repeat / g; <br> testStr.match (repeatRegex); <br> // Retorna ["Repetir", "Repetir", "Repetir"] </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Usando o regex <code>starRegex</code> , encontre e extraia ambas as palavras <code>"Twinkle"</code> da string <code>twinkleStar</code> . <strong>Nota</strong> <br> Você pode ter vários sinalizadores no seu regex como <code>/search/gi</code> </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex <code>starRegex</code> deve usar a bandeira 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: Seu regex <code>starRegex</code> deve usar a flag insensível a maiúsculas e 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: Sua correspondência deve corresponder a ambas as ocorrências da palavra <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: Seu <code>result</code> partida deve ter dois 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,67 @@
|
||||
---
|
||||
id: 587d7db7367417b2b2512b9c
|
||||
title: Find One or More Criminals in a Hunt
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Encontre um ou mais criminosos em uma caçada
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Hora de fazer uma pausa e testar suas novas habilidades de redação de regex. Um grupo de criminosos escapou da prisão e fugiu, mas você não sabe quantos. No entanto, você sabe que eles ficam juntos quando estão perto de outras pessoas. Você é responsável por encontrar todos os criminosos de uma só vez. Aqui está um exemplo para revisar como fazer isso: O regex <code>/z+/</code> corresponde à letra <code>z</code> quando aparece uma ou mais vezes seguidas. Ele encontraria correspondências em todas as seguintes strings: <blockquote> "z" <br> "zzzzzz" <br> "ABCzzzz" <br> "zzzzABC" <br> "abczzzzzzzzzzzzzzzzzzzzzabc" </blockquote> Mas ele não encontra correspondências nas strings a seguir, pois não há caracteres da letra <code>z</code> : <blockquote> "" <br> "ABC" <br> "abcabc" </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Escreva um regex <code>greedy</code> que encontre um ou mais criminosos dentro de um grupo de outras pessoas. Um criminoso é representado pela letra maiúscula <code>C</code> </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve corresponder a <code>one</code> criminoso (" <code>C</code> ") em <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: Seu regex deve coincidir com <code>two</code> criminosos (" <code>CC</code> ") em <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: Seu regex deve corresponder a <code>three</code> criminosos (" <code>CCC</code> ") em <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: Seu regex deve corresponder a <code>five</code> criminosos (" <code>CCCCC</code> ") em <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: Seu regex não deve corresponder a nenhum criminoso em <code>""</code>
|
||||
testString: 'assert(!reCriminals.test(""), "Your regex should not match any criminals in <code>""</code>");'
|
||||
- text: Seu regex não deve corresponder a nenhum criminoso em <code>"P1P2P3"</code>
|
||||
testString: 'assert(!reCriminals.test("P1P2P3"), "Your regex should not match any criminals in <code>"P1P2P3"</code>");'
|
||||
- text: Seu regex deve corresponder a <code>fifty</code> criminosos (" <code>CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC</code> ") em <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,69 @@
|
||||
---
|
||||
id: 587d7db4367417b2b2512b91
|
||||
title: Ignore Case While Matching
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Ignorar maiúsculas e minúsculas durante a correspondência
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Até agora, você observou as expressões regulares para fazer correspondências literais de strings. Mas, às vezes, você pode querer também combinar diferenças entre casos. Caso (ou, às vezes, letra maiúscula) é a diferença entre letras maiúsculas e minúsculas. Exemplos de maiúsculas são <code>"A"</code> , <code>"B"</code> e <code>"C"</code> . Exemplos de letras minúsculas são <code>"a"</code> , <code>"b"</code> e <code>"c"</code> . Você pode combinar os dois casos usando o que é chamado de flag. Existem outras bandeiras, mas aqui você se concentrará na bandeira que ignora maiúsculas e minúsculas - o sinalizador <code>i</code> . Você pode usá-lo anexando-o ao regex. Um exemplo de usar esse sinalizador é <code>/ignorecase/i</code> . Este regex pode coincidir com as strings <code>"ignorecase"</code> , <code>"igNoreCase"</code> e <code>"IgnoreCase"</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Escreva um regex <code>fccRegex</code> para combinar com <code>"freeCodeCamp"</code> , não importa o caso. Seu regex não deve corresponder a nenhuma abreviação ou variação com espaços. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve corresponder ao <code>freeCodeCamp</code>
|
||||
testString: 'assert(fccRegex.test("freeCodeCamp"), "Your regex should match <code>freeCodeCamp</code>");'
|
||||
- text: Seu regex deve corresponder ao <code>FreeCodeCamp</code>
|
||||
testString: 'assert(fccRegex.test("FreeCodeCamp"), "Your regex should match <code>FreeCodeCamp</code>");'
|
||||
- text: Seu regex deve corresponder ao <code>FreecodeCamp</code>
|
||||
testString: 'assert(fccRegex.test("FreecodeCamp"), "Your regex should match <code>FreecodeCamp</code>");'
|
||||
- text: Seu regex deve corresponder ao <code>FreeCodecamp</code>
|
||||
testString: 'assert(fccRegex.test("FreeCodecamp"), "Your regex should match <code>FreeCodecamp</code>");'
|
||||
- text: Seu regex não deve corresponder ao <code>Free Code Camp</code>
|
||||
testString: 'assert(!fccRegex.test("Free Code Camp"), "Your regex should not match <code>Free Code Camp</code>");'
|
||||
- text: Seu regex deve corresponder ao <code>FreeCOdeCamp</code>
|
||||
testString: 'assert(fccRegex.test("FreeCOdeCamp"), "Your regex should match <code>FreeCOdeCamp</code>");'
|
||||
- text: Seu regex não deve corresponder ao <code>FCC</code>
|
||||
testString: 'assert(!fccRegex.test("FCC"), "Your regex should not match <code>FCC</code>");'
|
||||
- text: Seu regex deve corresponder ao <code>FrEeCoDeCamp</code>
|
||||
testString: 'assert(fccRegex.test("FrEeCoDeCamp"), "Your regex should match <code>FrEeCoDeCamp</code>");'
|
||||
- text: Seu regex deve corresponder ao <code>FrEeCodECamp</code>
|
||||
testString: 'assert(fccRegex.test("FrEeCodECamp"), "Your regex should match <code>FrEeCodECamp</code>");'
|
||||
- text: Seu regex deve corresponder a <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,63 @@
|
||||
---
|
||||
id: 587d7db4367417b2b2512b90
|
||||
title: Match a Literal String with Different Possibilities
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Combine uma seqüência literal com diferentes possibilidades
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Usando regexes como <code>/coding/</code> , você pode procurar o padrão <code>"coding"</code> em outra string. Isso é poderoso para pesquisar strings únicas, mas é limitado a apenas um padrão. Você pode pesquisar vários padrões usando a <code>alternation</code> ou o operador <code>OR</code> : <code>|</code> . Este operador corresponde aos padrões antes ou depois dele. Por exemplo, se você quisesse combinar <code>"yes"</code> ou <code>"no"</code> , o regex desejado é <code>/yes|no/</code> . Você também pode pesquisar mais do que apenas dois padrões. Você pode fazer isso adicionando mais padrões com mais operadores <code>OR</code> separando-os, como <code>/yes|no|maybe/</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Complete o regex <code>petRegex</code> para combinar com os pets <code>"dog"</code> , <code>"cat"</code> , <code>"bird"</code> ou <code>"fish"</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex <code>petRegex</code> deve retornar <code>true</code> para a string <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: Seu regex <code>petRegex</code> deve retornar <code>false</code> para a string <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: Seu regex <code>petRegex</code> deve retornar <code>true</code> para a string <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: Seu regex <code>petRegex</code> deve retornar <code>true</code> para a string <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: Seu regex <code>petRegex</code> deve retornar <code>false</code> para a string <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: Seu regex <code>petRegex</code> deve retornar <code>true</code> para a string <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: Seu regex <code>petRegex</code> deve retornar <code>false</code> para a string <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,61 @@
|
||||
---
|
||||
id: 587d7db7367417b2b2512b9f
|
||||
title: Match All Letters and Numbers
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Corresponder todas as letras e números
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Usando classes de caracteres, você conseguiu pesquisar todas as letras do alfabeto com <code>[az]</code> . Esse tipo de classe de caracteres é comum o suficiente para que haja um atalho para ele, embora inclua alguns caracteres extras também. A classe de caractere mais próxima em JavaScript para corresponder ao alfabeto é <code>\w</code> . Este atalho é igual a <code>[A-Za-z0-9_]</code> . Essa classe de caracteres corresponde a letras maiúsculas e minúsculas mais números. Note que esta classe de caracteres também inclui o caractere de sublinhado ( <code>_</code> ). <blockquote> let longHand = / [A-Za-z0-9 _] + /; <br> deixe shortHand = / \ w + /; <br> deixe números = "42"; <br> deixe varNames = "important_var"; <br> longHand.test (números); // Retorna true <br> shortHand.test (números); // Retorna true <br> longHand.test (varNames); // Retorna true <br> shortHand.test (varNames); // Retorna true </blockquote> Essas classes de caracteres de atalho também são conhecidas como <code>shorthand character classes</code> . </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use a classe de caractere abreviada <code>\w</code> para contar o número de caracteres alfanuméricos em várias aspas e cadeias de caracteres. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve usar o sinalizador global.
|
||||
testString: 'assert(alphabetRegexV2.global, "Your regex should use the global flag.");'
|
||||
- text: Seu regex deve usar o caractere 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: Seu regex deve encontrar 31 caracteres alfanuméricos em <code>"The five boxing wizards jump quickly."</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: Seu regex deve encontrar 32 caracteres alfanuméricos em <code>"Pack my box with five dozen liquor jugs."</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: Seu regex deve encontrar 30 caracteres alfanuméricos em <code>"How vexingly quick daft zebras jump!"</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: Seu regex deve encontrar 36 caracteres alfanuméricos em <code>"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,65 @@
|
||||
---
|
||||
id: 587d7db8367417b2b2512ba1
|
||||
title: Match All Non-Numbers
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Corresponder a todos os não-números
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> O último desafio mostrou como procurar dígitos usando o atalho <code>\d</code> com letra minúscula <code>d</code> . Você também pode pesquisar por não-dígitos usando um atalho semelhante que use um <code>D</code> maiúsculo. O atalho para procurar caracteres não dígitos é <code>\D</code> Isso é igual à classe de caracteres <code>[^0-9]</code> , que procura um único caractere que não seja um número entre zero e nove. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use a classe de caractere abreviada para não dígitos <code>\D</code> para contar quantos não-dígitos estão em títulos de filme. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve usar o caractere de atalho para corresponder a caracteres não dígitos
|
||||
testString: 'assert(/\\D/.test(noNumRegex.source), "Your regex should use the shortcut character to match non-digit characters");'
|
||||
- text: Seu regex deve usar o sinalizador global.
|
||||
testString: 'assert(noNumRegex.global, "Your regex should use the global flag.");'
|
||||
- text: Seu regex não deve encontrar nenhum dígito em <code>"9"</code> .
|
||||
testString: 'assert("9".match(noNumRegex) == null, "Your regex should find no non-digits in <code>"9"</code>.");'
|
||||
- text: Seu regex deve encontrar 6 não dígitos em <code>"Catch 22"</code> .
|
||||
testString: 'assert("Catch 22".match(noNumRegex).length == 6, "Your regex should find 6 non-digits in <code>"Catch 22"</code>.");'
|
||||
- text: Seu regex deve encontrar 11 não-dígitos em <code>"101 Dalmatians"</code> .
|
||||
testString: 'assert("101 Dalmatians".match(noNumRegex).length == 11, "Your regex should find 11 non-digits in <code>"101 Dalmatians"</code>.");'
|
||||
- text: 'Seu regex deve encontrar 15 não dígitos em <code>"One, Two, Three"</code> .'
|
||||
testString: 'assert("One, Two, Three".match(noNumRegex).length == 15, "Your regex should find 15 non-digits in <code>"One, Two, Three"</code>.");'
|
||||
- text: Seu regex deve encontrar 12 não dígitos em <code>"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: 'Seu regex deve encontrar 17 não-dígitos em <code>"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,65 @@
|
||||
---
|
||||
id: 5d712346c441eddfaeb5bdef
|
||||
title: Match All Numbers
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Corresponder todos os números
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você aprendeu atalhos para padrões de string comuns, como alfanuméricos. Outro padrão comum é procurar apenas dígitos ou números. O atalho para procurar caracteres de dígitos é <code>\d</code> , com um <code>d</code> minúsculo. Isso é igual à classe de caracteres <code>[0-9]</code> , que procura um único caractere de qualquer número entre zero e nove. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use a classe de caractere abreviada <code>\d</code> para contar quantos dígitos estão em títulos de filmes. Números escritos ("seis" em vez de 6) não contam. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve usar o caractere de atalho para corresponder aos caracteres do dígito
|
||||
testString: 'assert(/\\d/.test(numRegex.source), "Your regex should use the shortcut character to match digit characters");'
|
||||
- text: Seu regex deve usar o sinalizador global.
|
||||
testString: 'assert(numRegex.global, "Your regex should use the global flag.");'
|
||||
- text: Seu regex deve encontrar um dígito em <code>"9"</code> .
|
||||
testString: 'assert("9".match(numRegex).length == 1, "Your regex should find 1 digit in <code>"9"</code>.");'
|
||||
- text: Seu regex deve encontrar dois dígitos em <code>"Catch 22"</code> .
|
||||
testString: 'assert("Catch 22".match(numRegex).length == 2, "Your regex should find 2 digits in <code>"Catch 22"</code>.");'
|
||||
- text: Seu regex deve encontrar 3 dígitos em <code>"101 Dalmatians"</code> .
|
||||
testString: 'assert("101 Dalmatians".match(numRegex).length == 3, "Your regex should find 3 digits in <code>"101 Dalmatians"</code>.");'
|
||||
- text: 'Seu regex não deve encontrar dígitos em <code>"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: Seu regex deve encontrar 2 dígitos em <code>"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: 'Seu regex deve encontrar 4 dígitos em <code>"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,69 @@
|
||||
---
|
||||
id: 587d7db5367417b2b2512b94
|
||||
title: Match Anything with Wildcard Period
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Combinar qualquer coisa com o período curinga
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Às vezes você não conhece (ou não precisa) os caracteres exatos em seus padrões. Pensar em todas as palavras que combinam, digamos, um erro ortográfico levaria muito tempo. Felizmente, você pode economizar tempo usando o caractere curinga: <code>.</code> O caractere curinga <code>.</code> irá corresponder a qualquer caractere. O curinga também é chamado de <code>dot</code> e <code>period</code> . Você pode usar o caractere curinga como qualquer outro caractere na regex. Por exemplo, se você quisesse combinar <code>"hug"</code> , <code>"huh"</code> , <code>"hut"</code> e <code>"hum"</code> , você pode usar o regex <code>/hu./</code> para combinar todas as quatro palavras. <blockquote> humStr = "Vou cantarolar uma canção"; <br> deixe hugStr = "Bear hug"; <br> vamos huRegex = /hu./; <br> humStr.match (huRegex); // Retorna ["hum"] <br> hugStr.match (huRegex); // Retorna ["abraço"] </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Complete o regex <code>unRegex</code> para que ele corresponda às strings <code>"run"</code> , <code>"sun"</code> , <code>"fun"</code> , <code>"pun"</code> , <code>"nun"</code> e <code>"bun"</code> . Seu regex deve usar o caractere curinga. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve usar o método <code>.test()</code> .
|
||||
testString: 'assert(code.match(/\.test\(.*\)/), "You should use the <code>.test()</code> method.");'
|
||||
- text: Você deve usar o caractere curinga em seu regex <code>unRegex</code>
|
||||
testString: 'assert(/\./.test(unRegex.source), "You should use the wildcard character in your regex <code>unRegex</code>");'
|
||||
- text: Seu regex <code>unRegex</code> deve combinar <code>"run"</code> em <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: Seu regex <code>unRegex</code> deve combinar <code>"sun"</code> em <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: Seu regex <code>unRegex</code> deve combinar <code>"fun"</code> em <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: Seu regex <code>unRegex</code> deve combinar <code>"pun"</code> em <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: Seu regex <code>unRegex</code> deve corresponder a <code>"nun"</code> em <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: Seu regex <code>unRegex</code> deve coincidir com <code>"bun"</code> em <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: Seu regex <code>unRegex</code> não deve corresponder <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: Seu regex <code>unRegex</code> não deve coincidir com <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,57 @@
|
||||
---
|
||||
id: 587d7db7367417b2b2512b9d
|
||||
title: Match Beginning String Patterns
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Combinar Padrões de Cordas Iniciais
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Desafios anteriores mostraram que expressões regulares podem ser usadas para procurar um número de correspondências. Eles também são usados para procurar padrões em posições específicas em strings. Em um desafio anterior, você usou o caractere <code>caret</code> ( <code>^</code> ) dentro de um <code>character set</code> para criar um <code>negated character set</code> no formato <code>[^thingsThatWillNotBeMatched]</code> . Fora de um <code>character set</code> , o <code>caret</code> é usado para procurar padrões no início das seqüências de caracteres. <blockquote> deixe firstString = "Ricky é o primeiro e pode ser encontrado"; <br> deixe firstRegex = / ^ Ricky /; <br> firstRegex.test (firstString); <br> // Retorna true <br> vamos notFirst = "Você não pode encontrar Ricky agora."; <br> firstRegex.test (notFirst); <br> // Retorna falso </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use o caractere de <code>caret</code> em um regex para localizar <code>"Cal"</code> apenas no início da string <code>rickyAndCal</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve procurar por <code>"Cal"</code> com uma letra maiúscula.
|
||||
testString: 'assert(calRegex.source == "^Cal", "Your regex should search for <code>"Cal"</code> with a capital letter.");'
|
||||
- text: Seu regex não deve usar sinalizadores.
|
||||
testString: 'assert(calRegex.flags == "", "Your regex should not use any flags.");'
|
||||
- text: Seu regex deve corresponder a <code>"Cal"</code> no início da string.
|
||||
testString: 'assert(calRegex.test("Cal and Ricky both like racing."), "Your regex should match <code>"Cal"</code> at the beginning of the string.");'
|
||||
- text: Seu regex não deve corresponder a <code>"Cal"</code> no meio de uma string.
|
||||
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,55 @@
|
||||
---
|
||||
id: 587d7db6367417b2b2512b99
|
||||
title: Match Characters that Occur One or More Times
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Corresponder caracteres que ocorrem uma ou mais vezes
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Às vezes, você precisa corresponder a um caractere (ou grupo de caracteres) que aparece uma ou mais vezes seguidas. Isso significa que ocorre pelo menos uma vez e pode ser repetido. Você pode usar o caractere <code>+</code> para verificar se é esse o caso. Lembre-se, o personagem ou padrão deve estar presente consecutivamente. Ou seja, o personagem tem que repetir um após o outro. Por exemplo, <code>/a+/g</code> encontraria uma correspondência em <code>"abc"</code> e retornaria <code>["a"]</code> . Por causa do <code>+</code> , ele também encontraria uma única correspondência em <code>"aabc"</code> e retornaria <code>["aa"]</code> . Se fosse em vez verificando a string <code>"abab"</code> , ele iria encontrar duas partidas e retornar <code>["a", "a"]</code> porque os <code>a</code> personagens não estão em uma linha - há um <code>b</code> entre eles. Finalmente, como não há <code>"a"</code> na string <code>"bcd"</code> , ele não encontrará uma correspondência. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Você quer encontrar correspondências quando a letra <code>s</code> ocorre uma ou mais vezes em <code>"Mississippi"</code> . Escreva um regex que use o sinal <code>+</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex <code>myRegex</code> deve usar o sinal <code>+</code> para corresponder a um ou mais caracteres <code>s</code> .
|
||||
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: Seu regex <code>myRegex</code> deve corresponder a 2 itens.
|
||||
testString: 'assert(result.length == 2, "Your regex <code>myRegex</code> should match 2 items.");'
|
||||
- text: A variável de <code>result</code> deve ser uma matriz com duas correspondências 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,59 @@
|
||||
---
|
||||
id: 587d7db6367417b2b2512b9a
|
||||
title: Match Characters that Occur Zero or More Times
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Corresponder caracteres que ocorrem zero ou mais vezes
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> O último desafio usou o sinal de mais <code>+</code> para procurar caracteres que ocorrem uma ou mais vezes. Há também uma opção que corresponde a caracteres que ocorrem zero ou mais vezes. O personagem para fazer isso é o <code>asterisk</code> ou <code>star</code> : <code>*</code> . <blockquote> deixe soccerWord = "gooooooooal!"; <br> deixe gPhrase = "pressentimento"; <br> deixe ophrase = "sobre a lua"; <br> deixe irRegex = / go * /; <br> soccerWord.match (goRegex); // Retorna ["goooooooo"] <br> gPhrase.match (goRegex); // Retorna ["g"] <br> oPhrase.match (goRegex); // Retorna nulo </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Crie um regex <code>chewieRegex</code> que use o caractere <code>*</code> para corresponder a todos os caracteres <code>"a"</code> superiores e inferiores em <code>chewieQuote</code> . Seu regex não precisa de sinalizadores e não deve corresponder a nenhuma das outras citações. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex <code>chewieRegex</code> deve usar o <code>*</code> caracteres para corresponder zero ou mais <code>a</code> caracteres.
|
||||
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: ''
|
||||
testString: 'assert(result[0].length === 16, "Your regex <code>chewieRegex</code> should match 16 characters.");'
|
||||
- text: Seu regex deve corresponder <code>"Aaaaaaaaaaaaaaaa"</code> .
|
||||
testString: 'assert(result[0] === "Aaaaaaaaaaaaaaaa", "Your regex should match <code>"Aaaaaaaaaaaaaaaa"</code>.");'
|
||||
- text: 'Seu regex não deve corresponder a nenhum personagem em <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: 'Seu regex não deve corresponder a nenhum caractere em <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,55 @@
|
||||
---
|
||||
id: 587d7db7367417b2b2512b9e
|
||||
title: Match Ending String Patterns
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Padrões de Sequência de Correspondência Final
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> No último desafio, você aprendeu a usar o caractere de <code>caret</code> para procurar padrões no início das seqüências de caracteres. Há também uma maneira de procurar padrões no final das strings. Você pode pesquisar o final das strings usando o caractere de <code>dollar sign</code> <code>$</code> no final da regex. <blockquote> deixe theEnding = "Esta é uma história sem fim"; <br> deixe storyRegex = / story $ /; <br> storyRegex.test (theEnding); <br> // Retorna true <br> deixe noEnding = "Às vezes uma história terá que terminar"; <br> storyRegex.test (noEnding); <br> // Retorna falso <br></blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use o caractere de âncora ( <code>$</code> ) para combinar com a string <code>"caboose"</code> no final do <code>caboose</code> string. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve procurar por <code>"caboose"</code> com o cifrão <code>$</code> anchor no seu regex.
|
||||
testString: 'assert(lastRegex.source == "caboose$", "You should search for <code>"caboose"</code> with the dollar sign <code>$</code> anchor in your regex.");'
|
||||
- text: Seu regex não deve usar sinalizadores.
|
||||
testString: 'assert(lastRegex.flags == "", "Your regex should not use any flags.");'
|
||||
- text: Você deve combinar <code>"caboose"</code> no final da corda <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,61 @@
|
||||
---
|
||||
id: 587d7db8367417b2b2512ba0
|
||||
title: Match Everything But Letters and Numbers
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: 'Combine tudo, mas letras e números'
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você aprendeu que pode usar um atalho para corresponder a alfanuméricos <code>[A-Za-z0-9_]</code> usando <code>\w</code> . Um padrão natural que você pode querer pesquisar é o oposto de alfanuméricos. Você pode procurar o oposto do <code>\w</code> com <code>\W</code> Note que o padrão oposto usa uma letra maiúscula. Este atalho é o mesmo que <code>[^A-Za-z0-9_]</code> . <blockquote> deixe shortHand = / \ W /; <br> deixar números = "42%"; <br> vamos sentenciar = "Codificação!"; <br> numbers.match (shortHand); // Retorna ["%"] <br> sentence.match (shortHand); // Retorna ["!"] <br></blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use a classe de caractere abreviada <code>\W</code> para contar o número de caracteres não alfanuméricos em várias aspas e cadeias de caracteres. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve usar o sinalizador global.
|
||||
testString: 'assert(nonAlphabetRegex.global, "Your regex should use the global flag.");'
|
||||
- text: Seu regex deve encontrar 6 caracteres não-alfanuméricos em <code>"The five boxing wizards jump quickly."</code> .
|
||||
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: Seu regex deve usar o caractere abreviado.
|
||||
testString: 'assert(/\\W/.test(nonAlphabetRegex.source), "Your regex should use the shorthand character to match characters which are non-alphanumeric.");'
|
||||
- text: Seu regex deve encontrar 8 caracteres não-alfanuméricos em <code>"Pack my box with five dozen liquor jugs."</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: Seu regex deve encontrar 6 caracteres não-alfanuméricos em <code>"How vexingly quick daft zebras jump!"</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: Seu regex deve encontrar 12 caracteres não-alfanuméricos em <code>"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,55 @@
|
||||
---
|
||||
id: 587d7db5367417b2b2512b96
|
||||
title: Match Letters of the Alphabet
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Correspondência de letras do alfabeto
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você viu como é possível usar <code>character sets</code> para especificar um grupo de caracteres a serem correspondidos, mas isso é muita digitação quando você precisa corresponder a um grande intervalo de caracteres (por exemplo, todas as letras do alfabeto). Felizmente, há um recurso embutido que torna isso simples e curto. Dentro de um <code>character set</code> , você pode definir um intervalo de caracteres para corresponder usando um caractere de <code>hyphen</code> : <code>-</code> . Por exemplo, para corresponder letras minúsculas de <code>a</code> até <code>e</code> você usaria <code>[ae]</code> . <blockquote> deixe catStr = "cat"; <br> deixe batStr = "bat"; <br> let matStr = "mat"; <br> deixe bgRegex = / [ae] em /; <br> catStr.match (bgRegex); // Retorna ["gato"] <br> batStr.match (bgRegex); // Retorna ["bat"] <br> matStr.match (bgRegex); // Retorna nulo </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Corresponder todas as letras da string <code>quoteSample</code> . <strong>Nota</strong> <br> Certifique-se de combinar as letras <strong>maiúsculas</strong> e minúsculas <strong><strong>.</strong></strong> </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex <code>alphabetRegex</code> deve corresponder a 35 itens.
|
||||
testString: 'assert(result.length == 35, "Your regex <code>alphabetRegex</code> should match 35 items.");'
|
||||
- text: Seu regex <code>alphabetRegex</code> deve usar o sinalizador global.
|
||||
testString: 'assert(alphabetRegex.flags.match(/g/).length == 1, "Your regex <code>alphabetRegex</code> should use the global flag.");'
|
||||
- text: Seu regex <code>alphabetRegex</code> deve usar o sinalizador insensível a maiúsculas e 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,55 @@
|
||||
---
|
||||
id: 587d7db3367417b2b2512b8f
|
||||
title: Match Literal Strings
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Combinar cordas literais
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> No último desafio, você pesquisou a palavra <code>"Hello"</code> usando a expressão regular <code>/Hello/</code> . Essa regex procurou por uma correspondência literal da string <code>"Hello"</code> . Aqui está outro exemplo em busca de uma correspondência literal da string <code>"Kevin"</code> : <blockquote> deixe testStr = "Olá, meu nome é Kevin."; <br> deixe testRegex = / Kevin /; <br> testRegex.test (testStr); <br> // Retorna true </blockquote> Qualquer outra forma de <code>"Kevin"</code> não será igual. Por exemplo, o regex <code>/Kevin/</code> não coincidirá com <code>"kevin"</code> ou <code>"KEVIN"</code> . <blockquote> vamos wrongRegex = / kevin /; <br> wrongRegex.test (testStr); <br> // Retorna falso </blockquote> Um desafio futuro mostrará como combinar esses outros formulários também. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Complete o regex <code>waldoRegex</code> para encontrar <code>"Waldo"</code> na string <code>waldoIsHiding</code> com uma correspondência literal. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex <code>waldoRegex</code> deve encontrar <code>"Waldo"</code>
|
||||
testString: 'assert(waldoRegex.test(waldoIsHiding), "Your regex <code>waldoRegex</code> should find <code>"Waldo"</code>");'
|
||||
- text: Seu regex <code>waldoRegex</code> não deve procurar por mais nada.
|
||||
testString: 'assert(!waldoRegex.test("Somewhere is hiding in this text."), "Your regex <code>waldoRegex</code> should not search for anything else.");'
|
||||
- text: Você deve executar uma correspondência literal de string com sua regex.
|
||||
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,59 @@
|
||||
---
|
||||
id: 587d7db9367417b2b2512ba4
|
||||
title: Match Non-Whitespace Characters
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Corresponder Personagens Não-Brancos
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você aprendeu sobre a pesquisa de espaço em branco usando <code>\s</code> , com um <code>s</code> minúsculo. Você também pode pesquisar tudo, exceto o espaço em branco. Procure por espaços não brancos usando <code>\S</code> , que é um <code>s</code> maiúsculo. Esse padrão não corresponderá a espaço em branco, retorno de carro, guia, feed de formulário e novos caracteres de linha. Você pode pensar que é semelhante à classe de caracteres <code>[^ \r\t\f\n\v]</code> . <blockquote> let whiteSpace = "Espaço em branco. Espaço em branco em todo lugar!" <br> deixe nonSpaceRegex = / \ S / g; <br> whiteSpace.match (nonSpaceRegex) .length; // retorna 32 </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere o <code>countNonWhiteSpace</code> da regex para procurar vários caracteres que não sejam espaços em branco em uma string. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve usar o sinalizador global.
|
||||
testString: 'assert(countNonWhiteSpace.global, "Your regex should use the global flag.");'
|
||||
- text: Seu regex deve usar o caractere abreviado
|
||||
testString: 'assert(/\\S/.test(countNonWhiteSpace.source), "Your regex should use the shorthand character <code>\S/code> to match all non-whitespace characters.");'
|
||||
- text: Seu regex deve encontrar 35 não-espaços em <code>"Men are from Mars and women are from 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: 'Seu regex deve encontrar 23 espaços diferentes em <code>"Space: the final frontier."</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: Seu regex deve encontrar 21 não espaços em <code>"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,55 @@
|
||||
---
|
||||
id: 587d7db5367417b2b2512b97
|
||||
title: Match Numbers and Letters of the Alphabet
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Corresponder números e letras do alfabeto
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Usar o hífen ( <code>-</code> ) para corresponder a um intervalo de caracteres não está limitado a letras. Ele também funciona para corresponder a um intervalo de números. Por exemplo, <code>/[0-5]/</code> corresponde a qualquer número entre <code>0</code> e <code>5</code> , incluindo <code>0</code> e <code>5</code> . Além disso, é possível combinar um intervalo de letras e números em um único conjunto de caracteres. <blockquote> deixe jennyStr = "Jenny8675309"; <br> deixe myRegex = / [a-z0-9] / ig; <br> // combina todas as letras e números em jennyStr <br> jennyStr.match (myRegex); </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Crie um único regex que corresponda a um intervalo de letras entre <code>h</code> <code>s</code> e um intervalo de números entre <code>2</code> e <code>6</code> . Lembre-se de incluir os sinalizadores apropriados na regex. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex <code>myRegex</code> deve corresponder a 17 itens.
|
||||
testString: 'assert(result.length == 17, "Your regex <code>myRegex</code> should match 17 items.");'
|
||||
- text: Seu regex <code>myRegex</code> deve usar o sinalizador global.
|
||||
testString: 'assert(myRegex.flags.match(/g/).length == 1, "Your regex <code>myRegex</code> should use the global flag.");'
|
||||
- text: Seu regex <code>myRegex</code> deve usar o sinalizador insensível a maiúsculas e 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,59 @@
|
||||
---
|
||||
id: 587d7db5367417b2b2512b95
|
||||
title: Match Single Character with Multiple Possibilities
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Corresponder personagem único com várias possibilidades
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você aprendeu como combinar padrões literais ( <code>/literal/</code> ) e caractere curinga ( <code>/./</code> ). Esses são os extremos de expressões regulares, onde se encontram correspondências exatas e o outro combina tudo. Existem opções que são um equilíbrio entre os dois extremos. Você pode procurar por um padrão literal com alguma flexibilidade com <code>character classes</code> . As classes de caracteres permitem que você defina um grupo de caracteres que deseja corresponder colocando-os dentro de colchetes ( <code>[</code> e <code>]</code> ). Por exemplo, você quer combinar <code>"bag"</code> , <code>"big"</code> e <code>"bug"</code> mas não <code>"bog"</code> . Você pode criar o regex <code>/b[aiu]g/</code> para fazer isso. O <code>[aiu]</code> é a classe de caracteres que corresponde apenas aos caracteres <code>"a"</code> , <code>"i"</code> ou <code>"u"</code> . <blockquote> deixe bigStr = "grande"; <br> vamos bagStr = "bag"; <br> deixe bugStr = "bug"; <br> deixe bogStr = "bog"; <br> deixe bgRegex = / b [aiu] g /; <br> bigStr.match (bgRegex); // Retorna ["grande"] <br> bagStr.match (bgRegex); // Retorna ["bag"] <br> bugStr.match (bgRegex); // Retorna ["bug"] <br> bogStr.match (bgRegex); // Retorna nulo </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use uma classe de caractere com vogais ( <code>a</code> , <code>e</code> , <code>i</code> , <code>o</code> , <code>u</code> ) em seu regex <code>vowelRegex</code> para encontrar todas as vogais na string <code>quoteSample</code> . <strong>Nota</strong> <br> Certifique-se de combinar as vogais maiúsculas e minúsculas. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve encontrar todas as 25 vogais.
|
||||
testString: 'assert(result.length == 25, "You should find all 25 vowels.");'
|
||||
- text: Seu regex <code>vowelRegex</code> deve usar uma classe de caracteres.
|
||||
testString: 'assert(/\[.*\]/.test(vowelRegex.source), "Your regex <code>vowelRegex</code> should use a character class.");'
|
||||
- text: Seu regex <code>vowelRegex</code> deve usar o sinalizador global.
|
||||
testString: 'assert(vowelRegex.flags.match(/g/).length == 1, "Your regex <code>vowelRegex</code> should use the global flag.");'
|
||||
- text: Seu regex <code>vowelRegex</code> deve usar o sinalizador insensível a maiúsculas e minúsculas.
|
||||
testString: 'assert(vowelRegex.flags.match(/i/).length == 1, "Your regex <code>vowelRegex</code> should use the case insensitive flag.");'
|
||||
- text: Seu regex não deve corresponder a nenhuma consoante.
|
||||
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,55 @@
|
||||
---
|
||||
id: 587d7db6367417b2b2512b98
|
||||
title: Match Single Characters Not Specified
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Combinar Caracteres Únicos Não Especificados
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Até agora, você criou um conjunto de caracteres que deseja corresponder, mas também pode criar um conjunto de caracteres que não deseja corresponder. Esses tipos de conjuntos de caracteres são chamados de <code>negated character sets</code> . Para criar um <code>negated character set</code> , coloque um caractere de <code>caret</code> ( <code>^</code> ) após o colchete de abertura e antes dos caracteres que você não deseja corresponder. Por exemplo, <code>/[^aeiou]/gi</code> combina todos os caracteres que não são uma vogal. Note que os personagens gostam <code>.</code> <code>!</code> , <code>[</code> , <code>@</code> , <code>/</code> E espaço em branco são combinados - o personagem vogal negada só definir exclui os caracteres de vogais. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Crie um único regex que corresponda a todos os caracteres que não sejam um número ou uma vogal. Lembre-se de incluir os sinalizadores apropriados na regex. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex <code>myRegex</code> deve corresponder a 9 itens.
|
||||
testString: 'assert(result.length == 9, "Your regex <code>myRegex</code> should match 9 items.");'
|
||||
- text: Seu regex <code>myRegex</code> deve usar o sinalizador global.
|
||||
testString: 'assert(myRegex.flags.match(/g/).length == 1, "Your regex <code>myRegex</code> should use the global flag.");'
|
||||
- text: Seu regex <code>myRegex</code> deve usar o sinalizador insensível a maiúsculas e 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,59 @@
|
||||
---
|
||||
id: 587d7db8367417b2b2512ba3
|
||||
title: Match Whitespace
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Corresponder espaço em branco
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Os desafios até agora cobriram letras correspondentes do alfabeto e números. Você também pode combinar o espaço em branco ou os espaços entre as letras. Você pode procurar espaços em branco usando <code>\s</code> , que é um <code>s</code> minúsculo. Esse padrão não apenas corresponde ao espaço em branco, mas também ao retorno de carro, à guia, ao feed de formulário e aos novos caracteres de linha. Você pode pensar nisso como semelhante à classe de caracteres <code>[ \r\t\f\n\v]</code> . <blockquote> let whiteSpace = "Espaço em branco. Espaço em branco em todo lugar!" <br> deixe spaceRegex = / \ s / g; <br> whiteSpace.match (spaceRegex); <br> // Retorna ["", ""] <br></blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere o regex <code>countWhiteSpace</code> para procurar vários caracteres de espaço em branco em uma string. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve usar o sinalizador global.
|
||||
testString: 'assert(countWhiteSpace.global, "Your regex should use the global flag.");'
|
||||
- text: Seu regex deve usar o caractere abreviado
|
||||
testString: 'assert(/\\s/.test(countWhiteSpace.source), "Your regex should use the shorthand character <code>\s</code> to match all whitespace characters.");'
|
||||
- text: Seu regex deve encontrar oito espaços em <code>"Men are from Mars and women are from 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: 'Seu regex deve encontrar três espaços em <code>"Space: the final frontier."</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: Seu regex não deve encontrar espaços em <code>"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,65 @@
|
||||
---
|
||||
id: 587d7dba367417b2b2512ba9
|
||||
title: Positive and Negative Lookahead
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Lookahead positivo e negativo
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> <code>Lookaheads</code> são padrões que dizem ao JavaScript para olhar em frente na sua string para verificar padrões mais adiante. Isso pode ser útil quando você deseja pesquisar vários padrões na mesma sequência. Existem dois tipos de <code>lookaheads</code> : <code>positive lookahead</code> e <code>negative lookahead</code> . Uma <code>positive lookahead</code> procurará garantir que o elemento no padrão de pesquisa esteja presente, mas não corresponderá a ele. Um lookahead positivo é usado como <code>(?=...)</code> onde o <code>...</code> é a parte requerida que não é correspondida. Por outro lado, um <code>negative lookahead</code> procurará garantir que o elemento no padrão de pesquisa não esteja lá. Um lookahead negativo é usado como <code>(?!...)</code> onde o <code>...</code> é o padrão que você não deseja estar lá. O restante do padrão será retornado se a parte lookahead negativa não estiver presente. Lookaheads são um pouco confusos, mas alguns exemplos vão ajudar. <blockquote> let quit = "qu"; <br> deixe noquit = "qt"; <br> deixe quRegex = / q (? = u) /; <br> deixe qRegex = / q (?! u) /; <br> quit.match (quRegex); // Retorna ["q"] <br> noquit.match (qRegex); // Retorna ["q"] </blockquote> Um uso mais prático de <code>lookaheads</code> é verificar dois ou mais padrões em uma string. Aqui está um verificador de senha (ingenuamente) simples que procura entre 3 e 6 caracteres e pelo menos um número: <blockquote> let password = "abc123"; <br> vamos checkPass = / (? = \ w {3,6}) (? = \ D * \ d) /; <br> checkPass.test (senha); // Retorna true </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use <code>lookaheads</code> no <code>pwRegex</code> para corresponder senhas com mais de 5 caracteres e dois dígitos consecutivos. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve usar dois positivos <code>lookaheads</code> .
|
||||
testString: 'assert(pwRegex.source.match(/\(\?=.*?\)\(\?=.*?\)/) !== null, "Your regex should use two positive <code>lookaheads</code>.");'
|
||||
- text: Seu regex não deve corresponder a <code>"astronaut"</code>
|
||||
testString: 'assert(!pwRegex.test("astronaut"), "Your regex should not match <code>"astronaut"</code>");'
|
||||
- text: Seu regex não deve corresponder a <code>"airplanes"</code>
|
||||
testString: 'assert(!pwRegex.test("airplanes"), "Your regex should not match <code>"airplanes"</code>");'
|
||||
- text: Seu regex não deve coincidir com <code>"banan1"</code>
|
||||
testString: 'assert(!pwRegex.test("banan1"), "Your regex should not match <code>"banan1"</code>");'
|
||||
- text: Seu regex deve coincidir com <code>"bana12"</code>
|
||||
testString: 'assert(pwRegex.test("bana12"), "Your regex should match <code>"bana12"</code>");'
|
||||
- text: Seu regex deve coincidir com <code>"abc123"</code>
|
||||
testString: 'assert(pwRegex.test("abc123"), "Your regex should match <code>"abc123"</code>");'
|
||||
- text: Seu regex não deve corresponder a <code>"123"</code>
|
||||
testString: 'assert(!pwRegex.test("123"), "Your regex should not match <code>"123"</code>");'
|
||||
- text: Seu regex não deve corresponder a <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
|
||||
// solution required
|
||||
```
|
||||
</section>
|
@ -0,0 +1,55 @@
|
||||
---
|
||||
id: 587d7dbb367417b2b2512bac
|
||||
title: Remove Whitespace from Start and End
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Remova o espaço em branco do início e do fim
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Às vezes, caracteres em branco ao redor de strings não são desejados, mas estão lá. O processamento típico de strings é remover o espaço em branco no início e no final dele. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Escreva um regex e use os métodos de string apropriados para remover os espaços em branco no início e no final das strings. <strong>Nota</strong> <br> O método <code>.trim()</code> funcionaria aqui, mas você precisará concluir esse desafio usando expressões regulares. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: '<code>result</code> deve ser igual a <code>"Hello, World!"</code>'
|
||||
testString: 'assert(result == "Hello, World!", "<code>result</code> should equal to <code>"Hello, World!"</code>");'
|
||||
- text: Você não deve usar o método <code>.trim()</code> .
|
||||
testString: 'assert(!code.match(/\.trim\(.*?\)/), "You should not use the <code>.trim()</code> method.");'
|
||||
- text: A variável de <code>result</code> não deve ser igual a uma string.
|
||||
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,61 @@
|
||||
---
|
||||
id: 587d7db8367417b2b2512ba2
|
||||
title: Restrict Possible Usernames
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Restringir nomes de usuário possíveis
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Os nomes de usuários são usados em toda a internet. Eles são o que dão aos usuários uma identidade única em seus sites favoritos. Você precisa verificar todos os nomes de usuários em um banco de dados. Aqui estão algumas regras simples que os usuários devem seguir ao criar seu nome de usuário. 1) Os únicos números no nome de usuário devem estar no final. Pode haver zero ou mais deles no final. 2) As letras do nome de usuário podem ser minúsculas e maiúsculas. 3) Nomes de usuários devem ter pelo menos dois caracteres. Um nome de usuário de duas letras só pode usar caracteres alfabéticos. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere o regex <code>userCheck</code> para ajustar as restrições listadas acima. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve corresponder ao <code>JACK</code>
|
||||
testString: 'assert(userCheck.test("JACK"), "Your regex should match <code>JACK</code>");'
|
||||
- text: Seu regex não deve corresponder a <code>J</code>
|
||||
testString: 'assert(!userCheck.test("J"), "Your regex should not match <code>J</code>");'
|
||||
- text: Seu regex deve corresponder a <code>Oceans11</code>
|
||||
testString: 'assert(userCheck.test("Oceans11"), "Your regex should match <code>Oceans11</code>");'
|
||||
- text: Seu regex deve corresponder ao <code>RegexGuru</code>
|
||||
testString: 'assert(userCheck.test("RegexGuru"), "Your regex should match <code>RegexGuru</code>");'
|
||||
- text: Seu regex não deve corresponder a <code>007</code>
|
||||
testString: 'assert(!userCheck.test("007"), "Your regex should not match <code>007</code>");'
|
||||
- text: Seu regex não deve corresponder a <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,69 @@
|
||||
---
|
||||
id: 587d7dbb367417b2b2512baa
|
||||
title: Reuse Patterns Using Capture Groups
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Reutilizar padrões usando grupos de captura
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Alguns padrões que você procura irão ocorrer várias vezes em uma string. É um desperdício repetir manualmente esse regex. Existe uma maneira melhor de especificar quando você tem várias substrings de repetição em sua string. Você pode pesquisar substrings de repetição usando <code>capture groups</code> . Parênteses, <code>(</code> e <code>)</code> , são usados para encontrar substrings de repetição. Você coloca o regex do padrão que será repetido entre os parênteses. Para especificar onde essa sequência de repetição aparecerá, use uma barra invertida ( <code>\</code> ) e, em seguida, um número. Esse número começa em 1 e aumenta com cada grupo de captura adicional usado. Um exemplo seria <code>\1</code> para corresponder ao primeiro grupo. O exemplo abaixo corresponde a qualquer palavra que ocorre duas vezes separada por um espaço: <blockquote> let repeatStr = "regex regex"; <br> deixe o repeatRegex = / (\ w +) \ s \ 1 /; <br> repeatRegex.test (repeatStr); // Retorna true <br> repeatStr.match (repeatRegex); // Retorna ["regex regex", "regex"] </blockquote> Usar o método <code>.match()</code> em uma string retornará uma matriz com a string correspondente, junto com seu grupo de captura. </section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Use <code>capture groups</code> em <code>reRegex</code> para corresponder números que são repetidos apenas três vezes em uma cadeia, cada um separado por um espaço. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve usar a classe de caractere abreviada para dígitos.
|
||||
testString: 'assert(reRegex.source.match(/\\d/), "Your regex should use the shorthand character class for digits.");'
|
||||
- text: Seu regex deve reutilizar o grupo de captura duas vezes.
|
||||
testString: 'assert(reRegex.source.match(/\\\d/g).length === 2, "Your regex should reuse the capture group twice.");'
|
||||
- text: Seu regex deve ter dois espaços separando os três números.
|
||||
testString: 'assert(reRegex.source.match(/\\s/g).length === 2, "Your regex should have two spaces separating the three numbers.");'
|
||||
- text: Seu regex deve corresponder <code>"42 42 42"</code> .
|
||||
testString: 'assert(reRegex.test("42 42 42"), "Your regex should match <code>"42 42 42"</code>.");'
|
||||
- text: Seu regex deve corresponder a <code>"100 100 100"</code> .
|
||||
testString: 'assert(reRegex.test("100 100 100"), "Your regex should match <code>"100 100 100"</code>.");'
|
||||
- text: Seu regex não deve corresponder a <code>"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: Seu regex não deve corresponder a <code>"42 42"</code> .
|
||||
testString: 'assert.equal(("42 42").match(reRegex.source), null, "Your regex should not match <code>"42 42"</code>.");'
|
||||
- text: Seu regex não deve coincidir com <code>"101 102 103"</code> .
|
||||
testString: 'assert(!reRegex.test("101 102 103"), "Your regex should not match <code>"101 102 103"</code>.");'
|
||||
- text: Seu regex não deve corresponder a <code>"1 2 3"</code> .
|
||||
testString: 'assert(!reRegex.test("1 2 3"), "Your regex should not match <code>"1 2 3"</code>.");'
|
||||
- text: Seu regex deve coincidir com <code>"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,61 @@
|
||||
---
|
||||
id: 587d7db9367417b2b2512ba7
|
||||
title: Specify Exact Number of Matches
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Especifique o Número Exato de Correspondências
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você pode especificar o número inferior e superior de padrões com <code>quantity specifiers</code> usando chaves. Às vezes você só quer um número específico de correspondências. Para especificar um certo número de padrões, basta ter esse número entre as chaves. Por exemplo, para corresponder apenas à palavra <code>"hah"</code> com a letra <code>a</code> <code>3</code> vezes, seu regex seria <code>/ha{3}h/</code> . <blockquote> deixe A4 = "haaaah"; <br> deixe A3 = "haaah"; <br> seja A100 = "h" + "a" .repetição (100) + "h"; <br> deixe multipleHA = / ha {3} h /; <br> multipleHA.test (A4); // Retorna falso <br> multipleHA.test (A3); // Retorna true <br> multipleHA.test (A100); // Retorna falso </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere o regex <code>timRegex</code> para coincidir com a palavra <code>"Timber"</code> somente quando tiver quatro letras <code>m</code> 's. </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve usar chaves.
|
||||
testString: 'assert(timRegex.source.match(/{.*?}/).length > 0, "Your regex should use curly brackets.");'
|
||||
- text: Seu regex não deve corresponder a <code>"Timber"</code>
|
||||
testString: 'assert(!timRegex.test("Timber"), "Your regex should not match <code>"Timber"</code>");'
|
||||
- text: Seu regex não deve corresponder a <code>"Timmber"</code>
|
||||
testString: 'assert(!timRegex.test("Timmber"), "Your regex should not match <code>"Timmber"</code>");'
|
||||
- text: Seu regex não deve corresponder a <code>"Timmmber"</code>
|
||||
testString: 'assert(!timRegex.test("Timmmber"), "Your regex should not match <code>"Timmmber"</code>");'
|
||||
- text: Seu regex deve corresponder a <code>"Timmmmber"</code>
|
||||
testString: 'assert(timRegex.test("Timmmmber"), "Your regex should match <code>"Timmmmber"</code>");'
|
||||
- text: 'Seu regex não deve corresponder a <code>"Timber"</code> com 30 <code>m</code> 's nele.'
|
||||
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,63 @@
|
||||
---
|
||||
id: 587d7db9367417b2b2512ba6
|
||||
title: Specify Only the Lower Number of Matches
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Especifique apenas o menor número de correspondências
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Você pode especificar o número inferior e superior de padrões com <code>quantity specifiers</code> usando chaves. Às vezes você só quer especificar o menor número de padrões sem limite superior. Para especificar apenas o menor número de padrões, mantenha o primeiro número seguido por uma vírgula. Por exemplo, para corresponder apenas à string <code>"hah"</code> com a letra <code>a</code> aparecer pelo menos <code>3</code> vezes, seu regex seria <code>/ha{3,}h/</code> . <blockquote> deixe A4 = "haaaah"; <br> seja A2 = "haah"; <br> seja A100 = "h" + "a" .repetição (100) + "h"; <br> vamos multipleA = / ha {3,} h /; <br> multipleA.test (A4); // Retorna true <br> multipleA.test (A2); // Retorna falso <br> multipleA.test (A100); // Retorna true </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere o regex <code>haRegex</code> para coincidir com a palavra <code>"Hazzah"</code> apenas quando tiver quatro ou mais letras <code>z</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve usar chaves.
|
||||
testString: 'assert(haRegex.source.match(/{.*?}/).length > 0, "Your regex should use curly brackets.");'
|
||||
- text: Seu regex não deve corresponder a <code>"Hazzah"</code>
|
||||
testString: 'assert(!haRegex.test("Hazzah"), "Your regex should not match <code>"Hazzah"</code>");'
|
||||
- text: Seu regex não deve corresponder a <code>"Hazzzah"</code>
|
||||
testString: 'assert(!haRegex.test("Hazzzah"), "Your regex should not match <code>"Hazzzah"</code>");'
|
||||
- text: Seu regex deve coincidir com <code>"Hazzzzah"</code>
|
||||
testString: 'assert(haRegex.test("Hazzzzah"), "Your regex should match <code>"Hazzzzah"</code>");'
|
||||
- text: Seu regex deve coincidir com <code>"Hazzzzzah"</code>
|
||||
testString: 'assert(haRegex.test("Hazzzzzah"), "Your regex should match <code>"Hazzzzzah"</code>");'
|
||||
- text: Seu regex deve coincidir com <code>"Hazzzzzzah"</code>
|
||||
testString: 'assert(haRegex.test("Hazzzzzzah"), "Your regex should match <code>"Hazzzzzzah"</code>");'
|
||||
- text: 'Seu regex deve combinar <code>"Hazzah"</code> com 30 <code>z</code> \ 's nele.'
|
||||
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,63 @@
|
||||
---
|
||||
id: 587d7db9367417b2b2512ba5
|
||||
title: Specify Upper and Lower Number of Matches
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Especifique o Número Superior e Inferior de Correspondências
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Lembre-se de usar o sinal de mais <code>+</code> para procurar um ou mais caracteres e o asterisco <code>*</code> para procurar zero ou mais caracteres. Estes são convenientes, mas às vezes você quer combinar um certo intervalo de padrões. Você pode especificar o número inferior e superior de padrões com <code>quantity specifiers</code> . Os especificadores de quantidade são usados com chaves ( <code>{</code> e <code>}</code> ). Você coloca dois números entre as chaves - para o número inferior e superior de padrões. Por exemplo, para corresponder apenas a letra <code>a</code> aparecer entre <code>3</code> e <code>5</code> vezes na seqüência de <code>"ah"</code> , o seu regex seria <code>/a{3,5}h/</code> . <blockquote> deixe A4 = "aaaah"; <br> deixe A2 = "aah"; <br> vamos multipleA = / a {3,5} h /; <br> multipleA.test (A4); // Retorna true <br> multipleA.test (A2); // Retorna falso </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Altere o regex <code>ohRegex</code> para corresponder apenas de <code>3</code> a <code>6</code> letras <code>h</code> na palavra <code>"Oh no"</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Seu regex deve usar chaves.
|
||||
testString: 'assert(ohRegex.source.match(/{.*?}/).length > 0, "Your regex should use curly brackets.");'
|
||||
- text: Seu regex não deve corresponder a <code>"Ohh no"</code>
|
||||
testString: 'assert(!ohRegex.test("Ohh no"), "Your regex should not match <code>"Ohh no"</code>");'
|
||||
- text: Seu regex deve combinar <code>"Ohhh no"</code>
|
||||
testString: 'assert(ohRegex.test("Ohhh no"), "Your regex should match <code>"Ohhh no"</code>");'
|
||||
- text: Seu regex deve combinar <code>"Ohhhh no"</code>
|
||||
testString: 'assert(ohRegex.test("Ohhhh no"), "Your regex should match <code>"Ohhhh no"</code>");'
|
||||
- text: Seu regex deve combinar <code>"Ohhhhh no"</code>
|
||||
testString: 'assert(ohRegex.test("Ohhhhh no"), "Your regex should match <code>"Ohhhhh no"</code>");'
|
||||
- text: Seu regex deve combinar <code>"Ohhhhhh no"</code>
|
||||
testString: 'assert(ohRegex.test("Ohhhhhh no"), "Your regex should match <code>"Ohhhhhh no"</code>");'
|
||||
- text: Seu regex não deve corresponder a <code>"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,56 @@
|
||||
---
|
||||
id: 587d7dbb367417b2b2512bab
|
||||
title: Use Capture Groups to Search and Replace
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Use grupos de captura para pesquisar e substituir
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Pesquisando é útil. No entanto, você pode tornar a pesquisa ainda mais poderosa quando ela também altera (ou substitui) o texto que você corresponde. Você pode pesquisar e substituir texto em uma string usando <code>.replace()</code> em uma string. As entradas para <code>.replace()</code> são primeiro o padrão regex que você deseja procurar. O segundo parâmetro é a string para substituir a correspondência ou uma função para fazer alguma coisa. <blockquote> vamos wrongText = "O céu é prateado."; <br> vamos silverRegex = / silver /; <br> wrongText.replace (silverRegex, "blue"); <br> // Retorna "O céu é azul." </blockquote> Você também pode acessar grupos de captura na sequência de substituição com sinais de cifrão ( <code>$</code> ). <blockquote> "Code Camp" .replace (/ (\ w +) \ s (\ w +) /, '$ 2 $ 1'); <br> // Retorna "Camp Code" </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Escreva um regex para que ele procure pela string <code>"good"</code> . Em seguida, atualize a variável <code>replaceText</code> para substituir <code>"good"</code> por <code>"okey-dokey"</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve usar <code>.replace()</code> para pesquisar e substituir.
|
||||
testString: 'assert(code.match(/\.replace\(.*\)/), "You should use <code>.replace()</code> to search and replace.");'
|
||||
- text: Seu regex deve mudar <code>"This sandwich is good."</code> para <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: Você não deve mudar a última linha.
|
||||
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,53 @@
|
||||
---
|
||||
id: 587d7db3367417b2b2512b8e
|
||||
title: Using the Test Method
|
||||
challengeType: 1
|
||||
videoUrl: ''
|
||||
localeTitle: Usando o método de teste
|
||||
---
|
||||
|
||||
## Description
|
||||
<section id="description"> Expressões regulares são usadas em linguagens de programação para corresponder partes de strings. Você cria padrões para ajudá-lo a fazer essa correspondência. Se você quiser encontrar a palavra <code>"the"</code> na string <code>"The dog chased the cat"</code> , você pode usar a seguinte expressão regular: <code>/the/</code> . Observe que as marcas de aspas não são necessárias na expressão regular. O JavaScript tem várias maneiras de usar regexes. Uma maneira de testar um regex é usando o método <code>.test()</code> . O método <code>.test()</code> pega o regex, aplica-o a uma string (que é colocada dentro dos parênteses) e retorna <code>true</code> ou <code>false</code> se o padrão encontrar algo ou não. <blockquote> deixe testStr = "freeCodeCamp"; <br> deixe testRegex = / Code /; <br> testRegex.test (testStr); <br> // Retorna true </blockquote></section>
|
||||
|
||||
## Instructions
|
||||
<section id="instructions"> Aplique o regex <code>myRegex</code> na string <code>myString</code> usando o método <code>.test()</code> . </section>
|
||||
|
||||
## Tests
|
||||
<section id='tests'>
|
||||
|
||||
```yml
|
||||
tests:
|
||||
- text: Você deve usar <code>.test()</code> para testar o regex.
|
||||
testString: 'assert(code.match(/myRegex.test\(\s*myString\s*\)/), "You should use <code>.test()</code> to test the regex.");'
|
||||
- text: Seu resultado deve retornar <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