4.8 KiB
4.8 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db5367417b2b2512b94 | Match Anything with Wildcard Period | 1 | Combinar qualquer coisa com o período curinga |
Description
.
O caractere curinga .
irá corresponder a qualquer caractere. O curinga também é chamado de dot
e period
. Você pode usar o caractere curinga como qualquer outro caractere na regex. Por exemplo, se você quisesse combinar "hug"
, "huh"
, "hut"
e "hum"
, você pode usar o regex /hu./
para combinar todas as quatro palavras. humStr = "Vou cantarolar uma canção";
deixe hugStr = "Bear hug";
vamos huRegex = /hu./;
humStr.match (huRegex); // Retorna ["hum"]
hugStr.match (huRegex); // Retorna ["abraço"]
Instructions
unRegex
para que ele corresponda às strings "run"
, "sun"
, "fun"
, "pun"
, "nun"
e "bun"
. Seu regex deve usar o caractere curinga. Tests
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>");'
Challenge Seed
let exampleStr = "Let's have fun with regular expressions!";
let unRegex = /change/; // Change this line
let result = unRegex.test(exampleStr);
Solution
// solution required