1.7 KiB
1.7 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7db4367417b2b2512b92 | Extract Matches | 1 | 提取匹配 |
Description
.match()
方法提取您找到的实际匹配项。要使用.match()
方法,请将该方法应用于字符串并传入括号内的正则表达式。这是一个例子: “你好,世界!”。匹配(/ Hello /);
//返回[“Hello”]
让ourStr =“正则表达式”;
让ourRegex = / expressions /;
ourStr.match(ourRegex);
//返回[“表达式”]
Instructions
.match()
方法来提取单词coding
。 Tests
tests:
- text: <code>result</code>应该有单词<code>coding</code>
testString: 'assert(result.join() === "coding", "The <code>result</code> should have the word <code>coding</code>");'
- text: 你的regex <code>codingRegex</code>应该搜索<code>coding</code>
testString: 'assert(codingRegex.source === "coding", "Your regex <code>codingRegex</code> should search for <code>coding</code>");'
- text: 您应该使用<code>.match()</code>方法。
testString: 'assert(code.match(/\.match\(.*\)/), "You should use the <code>.match()</code> method.");'
Challenge Seed
let extractStr = "Extract the word 'coding' from this string.";
let codingRegex = /change/; // Change this line
let result = extractStr; // Change this line
Solution
// solution required