freeCodeCamp/curriculum/challenges/portuguese/02-javascript-algorithms-an.../regular-expressions/match-literal-strings.portu...

2.3 KiB

id title challengeType videoUrl localeTitle
587d7db3367417b2b2512b8f Match Literal Strings 1 Combinar cordas literais

Description

No último desafio, você pesquisou a palavra "Hello" usando a expressão regular /Hello/ . Essa regex procurou por uma correspondência literal da string "Hello" . Aqui está outro exemplo em busca de uma correspondência literal da string "Kevin" :
deixe testStr = "Olá, meu nome é Kevin.";
deixe testRegex = / Kevin /;
testRegex.test (testStr);
// Retorna true
Qualquer outra forma de "Kevin" não será igual. Por exemplo, o regex /Kevin/ não coincidirá com "kevin" ou "KEVIN" .
vamos wrongRegex = / kevin /;
wrongRegex.test (testStr);
// Retorna falso
Um desafio futuro mostrará como combinar esses outros formulários também.

Instructions

Complete o regex waldoRegex para encontrar "Waldo" na string waldoIsHiding com uma correspondência literal.

Tests

tests:
  - text: Seu regex <code>waldoRegex</code> deve encontrar <code>&quot;Waldo&quot;</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.");'

Challenge Seed

let waldoIsHiding = "Somewhere Waldo is hiding in this text.";
let waldoRegex = /search/; // Change this line
let result = waldoRegex.test(waldoIsHiding);

Solution

// solution required