Word Counter
How This Converter Works
Counts non-empty runs of non-whitespace characters as words. Empty or whitespace-only input returns 0.
Formula or rule
Words = input.trim().match(/\S+/g) || []; count = Words.length.
Example
- Input
- red
blue sky - Calculation
- Whitespace separates the three non-empty word runs: red, blue, and sky.
- Result
- 3