+
号来查找出现一次或多次的字符。还有一个选项可以匹配出现零次或多次的字符。执行此操作的字符是asterisk
或star
asterisk
: *
。 让soccerWord =“gooooooooal!”;
让gPhrase =“直觉”;
让oPhrase =“越过月亮”;
let goRegex = / go * /;
soccerWord.match(goRegex); //返回[“goooooooo”]
gPhrase.match(goRegex); //返回[“g”]
oPhrase.match(goRegex); //返回null
chewieRegex
使用的*
字符匹配所有上下"a"
中的字符chewieQuote
。你的正则表达式不需要标志,它不应该与任何其他引号相匹配。 chewieRegex
应该使用*
字符匹配零个或多个a
字符。
testString: 'assert(/\*/.test(chewieRegex.source), "Your regex chewieRegex
should use the *
character to match zero or more a
characters.");'
- text: 你的正则表达式chewieRegex
应匹配16个字符。
testString: 'assert(result[0].length === 16, "Your regex chewieRegex
should match 16 characters.");'
- text: 你的正则表达式应该匹配"Aaaaaaaaaaaaaaaa"
。
testString: 'assert(result[0] === "Aaaaaaaaaaaaaaaa", "Your regex should match "Aaaaaaaaaaaaaaaa"
.");'
- text: '你的正则表达式不应该与"He made a fair move. Screaming about it can't help you."
中的任何角色相匹配"He made a fair move. Screaming about it can't help you."
'
testString: 'assert(!"He made a fair move. Screaming about it can\"t help you.".match(chewieRegex), "Your regex should not match any characters in "He made a fair move. Screaming about it can't help you."
");'
- text: '你的正则表达式不应该与"Let him have it. It's not wise to upset a Wookiee."
中的任何角色相匹配"Let him have it. It's not wise to upset a Wookiee."
'
testString: 'assert(!"Let him have it. It\"s not wise to upset a Wookiee.".match(chewieRegex), "Your regex should not match any characters in "Let him have it. It's not wise to upset a Wookiee."
");'
```