I added a 'word count' feature to my blog editor this morning. This is the regular expression to match spaces and line breaks:
/\s/
And in JavaScript:
const count = mystring.split(/\s+/).length;