2.4 KiB
2.4 KiB
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db6367417b2b2512b99 | Match Characters that Occur One or More Times | 1 | 匹配出现一次或多次的字符 |
Description
+
字符来检查是否是这种情况。请记住,角色或模式必须连续出现。也就是说,角色必须一个接一个地重复。例如, /a+/g
会在"abc"
找到一个匹配并返回["a"]
。由于+
,它也会在"aabc"
找到一个匹配并返回["aa"]
。如果它是检查字符串"abab"
,它会找到两个匹配并返回["a", "a"]
因为a
字符不在一行 - 它们之间有一个b
。最后,由于字符串"bcd"
没有"a"
"bcd"
,因此找不到匹配项。 Instructions
"Mississippi"
字母s
出现一次或多次时找到匹配项。写一个使用+
符号的正则表达式。 Tests
tests:
- text: 你的正则表达式<code>myRegex</code>应该使用<code>+</code>符号来匹配一个或多个<code>s</code>字符。
testString: 'assert(/\+/.test(myRegex.source), "Your regex <code>myRegex</code> should use the <code>+</code> sign to match one or more <code>s</code> characters.");'
- text: 你的正则表达式<code>myRegex</code>应该匹配2个项目。
testString: 'assert(result.length == 2, "Your regex <code>myRegex</code> should match 2 items.");'
- text: <code>result</code>变量应该是一个包含两个匹配<code>"ss"</code>的数组
testString: 'assert(result[0] == "ss" && result[1] == "ss", "The <code>result</code> variable should be an array with two matches of <code>"ss"</code>");'
Challenge Seed
let difficultSpelling = "Mississippi";
let myRegex = /change/; // Change this line
let result = difficultSpelling.match(myRegex);
Solution
// solution required