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 😉
More Related Contents:
- Regex – To allow numeric, only characters R, N, X, B, @ [closed]
- Find particular string from URL in JavaScript
- Negative lookbehind equivalent in JavaScript
- JavaScript regex multiline text between two tags
- Case insensitive regex in JavaScript
- Remove not alphanumeric characters from string
- Count number of matches of a regex in Javascript
- Password REGEX with min 6 chars, at least one letter and one number and may contain special characters
- Regex created via new RegExp(myString) not working (backslashes)
- Replace a Regex capture group with uppercase in Javascript
- How to write regex to validate dates?
- Replacing from javascript dom text node
- Javascript Regex to replace text NOT in html attributes [duplicate]
- Replacing the nth instance of a regex match in Javascript
- How to extract a string using JavaScript Regex?
- JavaScript Regex Global Match Groups
- How can I put [] (square brackets) in RegExp javascript?
- Interesting test of Javascript RegExp [duplicate]
- Javascript Regex to match only a single occurrence no more or less
- All characters in a string must match regex
- RegEx to match stuff between parentheses
- Regex eError when using {1}+ possessive quantifier in JavaScript regex
- Check if string contains only letters in javascript
- Regular Expression Pattern With A Variable
- Regex JavaScript image file extension [closed]
- Removing backslashes from strings in javascript
- Why this regex is not working for german words?
- I would like to mimick conditionals in javascript regex
- Get text between two rounded brackets
- Preg_match to regex equivalent expression to match any Unicode letters