.match()
方法提取您找到的实际匹配项。要使用.match()
方法,请将该方法应用于字符串并传入括号内的正则表达式。这是一个例子: “你好,世界!”。匹配(/ Hello /);
//返回[“Hello”]
让ourStr =“正则表达式”;
让ourRegex = / expressions /;
ourStr.match(ourRegex);
//返回[“表达式”]
.match()
方法来提取单词coding
。 result
应该有单词coding
testString: 'assert(result.join() === "coding", "The result
should have the word coding
");'
- text: 你的regex codingRegex
应该搜索coding
testString: 'assert(codingRegex.source === "coding", "Your regex codingRegex
should search for coding
");'
- text: 您应该使用.match()
方法。
testString: 'assert(code.match(/\.match\(.*\)/), "You should use the .match()
method.");'
```