Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript count words in string

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #count #words #string
ADD COMMENT
Topic
Name
3+4 =