+
来查找出现一次或多次的字符。还有一个选项可以匹配出现零次或多次的字符。
执行该操作的字符叫做asterisk
或star
,即*
。
```js
let soccerWord = "gooooooooal!";
let gPhrase = "gut feeling";
let oPhrase = "over the moon";
let goRegex = /go*/;
soccerWord.match(goRegex); // Returns ["goooooooo"]
gPhrase.match(goRegex); // Returns ["g"]
oPhrase.match(goRegex); // Returns null
```
chewieQuote
已经被初始化为 "Aaaaaaaaaaaaaaaarrrgh!"。创建一个变量为chewieRegex
的正则表达式,使用*
符号在chewieQuote
中匹配"A"
及其之后出现的零个或多个"a"
。你的正则表达式不需要使用修饰符,也不需要匹配引号。
chewieRegex
应该使用*
符号匹配'A'
之后出现的零个或多个'a'
字符。"
testString: assert(/\*/.test(chewieRegex.source));
- text: 正则表达式应当匹配 chewieQuote
里的 "A"
。
testString: assert(result[0][0] === 'A');
- text: "你的正则表达式应该匹配'Aaaaaaaaaaaaaaaa'
。"
testString: assert(result[0] === 'Aaaaaaaaaaaaaaaa');
- text: 你的正则表达式chewieRegex
应该匹配 16 个字符。
testString: assert(result[0].length === 16);
- text: "你的正则表达式在'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));
- text: "你的正则表达式在'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));
```