📅  最后修改于: 2022-03-11 15:03:39.657000             🧑  作者: Mango
var str = "your long string with many words.";
var wordCount = str.match(/(\w+)/g).length;
alert(wordCount); //6
// \w+ between one and unlimited word characters
// /g greedy - don't stop after the first match