5.4 KiB
5.4 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db5367417b2b2512b94 | Match Anything with Wildcard Period | 1 | 匹配通配符期间的任何内容 |
Description
.
通配符.
将匹配任何一个字符。通配符也称为dot
和period
。您可以像使用正则表达式中的任何其他字符一样使用通配符。例如,如果你想匹配"hug"
, "huh"
, "hut"
和"hum"
,你可以使用正则表达式/hu./
来匹配所有四个单词。 让humStr =“我会哼唱一首歌”;
让hugStr =“熊抱”;
让huRegex = /hu./;
humStr.match(huRegex); //返回[“hum”]
hugStr.match(huRegex); //返回[“拥抱”]
Instructions
unRegex
,使其匹配字符串"run"
, "sun"
, "fun"
, "pun"
, "nun"
和"bun"
。你的正则表达式应该使用通配符。 Tests
tests:
- text: 您应该使用<code>.test()</code>方法。
testString: 'assert(code.match(/\.test\(.*\)/), "You should use the <code>.test()</code> method.");'
- text: 您应该在正则表达式<code>unRegex</code>使用通配符
testString: 'assert(/\./.test(unRegex.source), "You should use the wildcard character in your regex <code>unRegex</code>");'
- text: 你的正则表达式<code>unRegex</code>应该匹配<code>"run"</code> <code>"Let us go on a run."</code> <code>"run"</code>中的<code>"run"</code> <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: 你的正则表达式<code>unRegex</code>应该与<code>"sun"</code> <code>"The sun is out today."</code> <code>"sun"</code>中的<code>"sun"</code>匹配<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: 你的正则表达式<code>unRegex</code>应该与<code>"fun"</code> <code>"Coding is a lot of fun."</code> <code>"fun"</code>中的<code>"fun"</code>匹配<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: 你的正则表达式<code>unRegex</code>应该匹配<code>"pun"</code> <code>"Seven days without a pun makes one weak."</code> <code>"pun"</code> <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: 你的正则表达式<code>unRegex</code>应该与<code>"nun"</code> <code>"One takes a vow to be a nun."</code> <code>"nun"</code>中的<code>"nun"</code>匹配<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: 你的正则表达式<code>unRegex</code>应该匹配<code>"bun"</code> <code>"She got fired from the hot dog stand for putting her hair in a bun."</code> <code>"bun"</code>中的<code>"bun"</code> <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: 您的正则表达式<code>unRegex</code>不应与<code>"There is a bug in my code."</code>匹配<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: 您的正则表达式<code>unRegex</code>不应该匹配<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