String Functions
String Word Count
Count the number of words in any text. Hyphenated words and contractions count as one word.
About counting words in text
This tool counts the number of words in whatever text you paste into the box on this page. Click Submit and the count appears immediately — nothing is uploaded or logged, the whole computation runs in your browser. It answers the same question as a word processor's status bar, but for text you're editing outside of one: a blog draft before you paste it into a CMS with a minimum-word SEO target, an abstract with a hard cap, or a product description you need to trim.
Under the hood the count comes from one regular expression, /[A-Za-z]+(?:['-][A-Za-z]+)*/g, matched against the input with String.match() and counted. A "word" is a run of Latin letters that can continue through an internal apostrophe or hyphen, so don't and well-known each count as one word, not two. This mirrors PHP's str_word_count() default mode, which the legacy server-rendered version of this tool called. Because the pattern only recognizes A-Za-z, a run of digits isn't a word at all, and a letter with a diacritic (café, naïve) can undercount or split, since the accent breaks the match instead of extending it.
Word counts matter anywhere there's a limit to hit: a minimum for SEO content, a maximum for a meta description or tweet, an academic abstract's hard cap, or a translated string that needs to land close to the source length. It's also a fast sanity check on pasted content — confirm a scraped snippet, a CMS field, or placeholder copy is the length you expect before it ships, without opening a word processor just to check.
Examples
const text = "Count the words in this short example sentence.";
const words = text.match(/[A-Za-z]+(?:['-][A-Za-z]+)*/g);
console.log(words);
// ["Count","the","words","in","this","short","example","sentence"]
console.log(words.length); // 8This is the exact expression the tool runs against your input on Submit — every run of letters is one word; a - or ' inside a run doesn't break it.
const text = "I have 2 cats and 3 dogs.";
text.split(/\s+/).filter(Boolean).length;
// 7 — every whitespace-separated token, including "2" and "3"
text.match(/[A-Za-z]+(?:['-][A-Za-z]+)*/g).length;
// 5 — only letter runs count; standalone digits don'tA naive .split(' ').length counter treats 2 and 3 as words because they're whitespace-separated tokens. This tool's letter-only regex doesn't count them — closer to how PHP's str_word_count() defines a word.
<p class='intro'>Hello world.</p>
→ 6 words (p, class, intro, Hello, world, p)
Hello world.
→ 2 wordsTag names and attribute values are letters too, so pasting markup directly overcounts. Strip tags first with the HTML Tags Remover for an accurate prose count.
Frequently asked questions
Does a hyphenated word or a contraction count as one word or two?
One. The matching pattern keeps a hyphen or apostrophe inside a run of letters, so well-known and don't each count as a single word rather than splitting into two.
Why doesn't a number like 2024 count as a word?
The count only matches Latin letters (A-Za-z). In I have 2 cats, the result is 3 words — I, have, cats — because 2 has no letters to match. A string made entirely of digits, like 2024, counts as 0 words.
Does it handle accented letters correctly, like in café or naïve?
Not reliably. Only A-Za-z counts as a letter, so an accent can split a word in two — naïve counts as 2 words (na, ve) — or truncate it, since café counts as one word missing its é. Treat the count as approximate for text with heavy accenting.
Should I strip HTML tags before counting words?
Yes, if you're pasting markup. Tag names and attribute values are letters too, so <p class='intro'>Hello world.</p> counts as 6 words instead of the 2 words a reader would actually see. Run the text through the HTML Tags Remover first for an accurate count.
Will this match the word count in Microsoft Word or Google Docs?
Approximately, not exactly. Word processors use more elaborate, locale-aware tokenizers, while this tool runs a single regular expression that only recognizes A-Za-z letters plus internal hyphens and apostrophes — closer to PHP's str_word_count() default mode. Expect the numbers to line up for plain English prose and drift slightly for text with heavy accenting or symbols.