Files

3.0 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7db5367417b2b2512b94 Encontrar qualquer coisa com o caractere curinga 1 301348 match-anything-with-wildcard-period

--description--

Haverá vezes em que você não saberá (ou não precisará saber) quais caracteres exatamente farão parte das suas regexes. Pensar em todas as palavras que capturariam, digamos, um erro ortográfico levaria muito tempo. Por sorte, você pode economizar tempo usando o caractere curinga: .

O caractere curinga . captura qualquer caractere. O curinga também pode ser chamado de ponto. Você pode usar o curinga como qualquer outro caractere na regex. Por exemplo, se você quiser encontrar hug, huh, hut ou hum, você pode usar a regex /hu./ para capturar todas as quatro palavras.

let humStr = "I'll hum a song";
let hugStr = "Bear hug";
let huRegex = /hu./;
huRegex.test(humStr);
huRegex.test(hugStr);

As duas chamadas a test retornam true.

--instructions--

Complete a regex unRegex para que ela encontre as strings run, sun, fun, pun, nun e bun. A regex deve usar o caractere curinga.

--hints--

Você deve usar o método .test().

assert(code.match(/\.test\(.*\)/));

Você deve usar o caractere curinga na regex unRegex

assert(/\./.test(unRegex.source));

A regex unRegex deve encontrar run na string Let us go on a run.

unRegex.lastIndex = 0;
assert(unRegex.test('Let us go on a run.'));

A regex unRegex deve encontrar sun na string The sun is out today.

unRegex.lastIndex = 0;
assert(unRegex.test('The sun is out today.'));

A regex unRegex deve encontrar fun na string Coding is a lot of fun.

unRegex.lastIndex = 0;
assert(unRegex.test('Coding is a lot of fun.'));

A regex unRegex deve encontrar pun na string Seven days without a pun makes one weak.

unRegex.lastIndex = 0;
assert(unRegex.test('Seven days without a pun makes one weak.'));

A regex unRegex deve encontrar nun na string One takes a vow to be a nun.

unRegex.lastIndex = 0;
assert(unRegex.test('One takes a vow to be a nun.'));

A regex unRegex deve encontrar bun na string She got fired from the hot dog stand for putting her hair in a bun.

unRegex.lastIndex = 0;
assert(
  unRegex.test(
    'She got fired from the hot dog stand for putting her hair in a bun.'
  )
);

A regex unRegex não deve incluir a string There is a bug in my code. no resultado

unRegex.lastIndex = 0;
assert(!unRegex.test('There is a bug in my code.'));

A regex unRegex não deve incluir a string Catch me if you can. no resultado

unRegex.lastIndex = 0;
assert(!unRegex.test('Catch me if you can.'));

--seed--

--seed-contents--

let exampleStr = "Let's have fun with regular expressions!";
let unRegex = /change/; // Change this line
let result = unRegex.test(exampleStr);

--solutions--

let exampleStr = "Let's have fun with regular expressions!";
let unRegex = /.un/; // Change this line
let result = unRegex.test(exampleStr);