I\'m trying to put together a regular expression for a JavaScript command that accurately counts the number of words in a textarea.
One solution I had found is as fo
This should do what you're after:
value.match(/\S+/g).length;
Rather than splitting the string, you're matching on any sequence of non-whitespace characters.
There's the added bonus of being easily able to extract each word if needed ;)