让testStr =“重复,重复,重复”;要多次搜索或提取模式,可以使用
让ourRegex = /重复/;
testStr.match(ourRegex);
//返回[“重复”]
g标志。 let repeatRegex = / Repeat / g;
testStr.match(repeatRegex);
//返回[“重复”,“重复”,“重复”]
starRegex ,找到并提取字符串twinkleStar "Twinkle"单词。 注意 /search/gi starRegex应该使用全局标志g
testString: assert(starRegex.flags.match(/g/).length == 1);
- text: 你的正则表达式starRegex应该使用不区分大小写的标志i
testString: assert(starRegex.flags.match(/i/).length == 1);
- text: 您的匹配应匹配"Twinkle"一词的出现次数
testString: assert(result.sort().join() == twinkleStar.match(/twinkle/gi).sort().join());
- text: 您的匹配result应该包含两个元素。
testString: assert(result.length == 2);
```