Open zilongxuan001 opened 6 years ago
代码为
// Setup
var testString = "How many";
// Only change code below this line.
var expression = /\S/g; // Change this line
// Only change code above this line
// This code counts the matches of expression in testString
var nonSpaceCount = testString.match(expression).length;
结果为
算出来的是字母的个数,不是单词的个数。
介绍
/s
可以匹配空白字符。/S
可以匹配任何非空白字符,计算出所有feiko非空白字母的个数。方法
练习
代码
结果显示
来源
https://www.freecodecamp.org/challenges/invert-regular-expression-matches-with-javascript