2.2 KiB
2.2 KiB
id, title, challengeType, forumTopicId, localeTitle
id | title | challengeType | forumTopicId | localeTitle |
---|---|---|---|---|
587d7db6367417b2b2512b99 | Match Characters that Occur One or More Times | 1 | 301350 | 匹配出现一次或多次的字符 |
Description
+
符号来检查情况是否如此。记住,字符或匹配模式必须一个接一个地连续出现。
例如,/a+/g
会在"abc"
中匹配到一个匹配项,并且返回["a"]
。因为+
的存在,它也会在"aabc"
中匹配到一个匹配项,然后返回["aa"]
。
如果它是检查字符串"abab"
,它将匹配到两个匹配项并且返回["a", "a"]
,因为a
字符不连续,在它们之间有一个b
字符。最后,因为在字符串"bcd"
中没有"a"
,因此找不到匹配项。
Instructions
"Mississippi"
中匹配到出现一次或多次的字母s
的匹配项。编写一个使用+
符号的正则表达式。
Tests
tests:
- text: 你的正则表达式<code>myRegex</code>应该使用<code>+</code>符号来匹配一个或多个<code>s</code>字符。
testString: assert(/\+/.test(myRegex.source));
- text: 你的正则表达式<code>myRegex</code>应该匹配两项。
testString: assert(result.length == 2);
- text: "<code>结果</code>变量应该是一个包含两个<code>'ss'</code>匹配项的数组。"
testString: assert(result[0] == 'ss' && result[1] == 'ss');
Challenge Seed
let difficultSpelling = "Mississippi";
let myRegex = /change/; // Change this line
let result = difficultSpelling.match(myRegex);
Solution
let difficultSpelling = "Mississippi";
let myRegex = /s+/g; // Change this line
let result = difficultSpelling.match(myRegex);