.
通配符.
将匹配任何一个字符。通配符也称为dot
和period
。您可以像使用正则表达式中的任何其他字符一样使用通配符。例如,如果你想匹配"hug"
, "huh"
, "hut"
和"hum"
,你可以使用正则表达式/hu./
来匹配所有四个单词。 让humStr =“我会哼唱一首歌”;
让hugStr =“熊抱”;
让huRegex = /hu./;
humStr.match(huRegex); //返回[“hum”]
hugStr.match(huRegex); //返回[“拥抱”]
unRegex
,使其匹配字符串"run"
, "sun"
, "fun"
, "pun"
, "nun"
和"bun"
。你的正则表达式应该使用通配符。 .test()
方法。
testString: assert(code.match(/\.test\(.*\)/));
- text: 您应该在正则表达式unRegex
使用通配符
testString: assert(/\./.test(unRegex.source));
- text: 你的正则表达式unRegex
应该匹配"run"
"Let us go on a run."
"run"
中的"run"
"Let us go on a run."
testString: assert(unRegex.test("Let us go on a run."));
- text: 你的正则表达式unRegex
应该与"sun"
"The sun is out today."
"sun"
中的"sun"
匹配"The sun is out today."
testString: assert(unRegex.test("The sun is out today."));
- text: 你的正则表达式unRegex
应该与"fun"
"Coding is a lot of fun."
"fun"
中的"fun"
匹配"Coding is a lot of fun."
testString: assert(unRegex.test("Coding is a lot of fun."));
- text: 你的正则表达式unRegex
应该匹配"pun"
"Seven days without a pun makes one weak."
"pun"
"Seven days without a pun makes one weak."
testString: assert(unRegex.test("Seven days without a pun makes one weak."));
- text: 你的正则表达式unRegex
应该与"nun"
"One takes a vow to be a nun."
"nun"
中的"nun"
匹配"One takes a vow to be a nun."
testString: assert(unRegex.test("One takes a vow to be a nun."));
- text: 你的正则表达式unRegex
应该匹配"bun"
"She got fired from the hot dog stand for putting her hair in a bun."
"bun"
中的"bun"
"She got fired from the hot dog stand for putting her hair in a bun."
testString: assert(unRegex.test("She got fired from the hot dog stand for putting her hair in a bun."));
- text: 您的正则表达式unRegex
不应与"There is a bug in my code."
匹配"There is a bug in my code."
testString: assert(!unRegex.test("There is a bug in my code."));
- text: 您的正则表达式unRegex
不应该匹配"Catch me if you can."
testString: assert(!unRegex.test("Can me if you can."));
```