--- id: 587d7db4367417b2b2512b93 title: Find More Than the First Match challengeType: 1 videoUrl: '' localeTitle: 找到比第一场比赛更多的东西 --- ## Description
到目前为止,您只能提取或搜索一次模式。
让testStr =“重复,重复,重复”;
让ourRegex = /重复/;
testStr.match(ourRegex);
//返回[“重复”]
要多次搜索或提取模式,可以使用g标志。
let repeatRegex = / Repeat / g;
testStr.match(repeatRegex);
//返回[“重复”,“重复”,“重复”]
## Instructions
使用正则表达式starRegex ,找到并提取字符串twinkleStar "Twinkle"单词。 注意
你可以在你的正则表达式上有多个标志,比如/search/gi
## Tests
```yml tests: - text: 你的正则表达式starRegex应该使用全局标志g testString: 'assert(starRegex.flags.match(/g/).length == 1, "Your regex starRegex should use the global flag g");' - text: 你的正则表达式starRegex应该使用不区分大小写的标志i testString: 'assert(starRegex.flags.match(/i/).length == 1, "Your regex starRegex should use the case insensitive flag i");' - text: 您的匹配应匹配"Twinkle"一词的出现次数 testString: 'assert(result.sort().join() == twinkleStar.match(/twinkle/gi).sort().join(), "Your match should match both occurrences of the word "Twinkle"");' - text: 您的匹配result应该包含两个元素。 testString: 'assert(result.length == 2, "Your match result should have two elements in it.");' ```
## Challenge Seed
```js let twinkleStar = "Twinkle, twinkle, little star"; let starRegex = /change/; // Change this line let result = twinkleStar; // Change this line ```
## Solution
```js // solution required ```