Article Word Counter: How to Count Words in Text
Learn what an article word counter actually counts, how to count words with common tools, and how to check the result when hyphens, contractions or markup are involved.
What an article word counter does
An article word counter takes a piece of text as input, such as a draft, a pasted web page or a plain-text file, and returns a number: how many words it contains. Many counters also report characters, sentences or paragraphs, but the word count is usually the figure that matters for submission limits, assignment requirements or editorial targets.
Counting is a read-only operation. It does not change your text. What changes from one tool to another is the definition of a word. The process of splitting text into countable units is called tokenization, and each unit is a token. Two counters can return different totals for the same article because they tokenize differently, not because one of them is broken.
Most counters use one of two approaches:
- Whitespace splitting: every run of characters between spaces, tabs or line breaks counts as one word. Punctuation stays attached to the word next to it, and a stray symbol surrounded by spaces counts as a word.
- Pattern matching: a regular expression (a text pattern) defines what a word looks like, typically a run of letters and digits. Punctuation-only tokens are ignored, but contractions and hyphenated words may be split unless the pattern allows for them.
Before you count, decide what belongs in the article total. Titles, headings, image captions, footnotes, reference lists and author bios are included by some requirements and excluded by others. If a publisher or instructor sets a limit, their rule decides this, not the counter.
How tokenization choices change the count
The following sample sentence is an illustrative example. It contains a straight apostrophe, a hyphen and two em dashes (the long dash, Unicode U+2014) with no spaces around them:
Don't over-edit: the draft—about 3 pages—is fine.
Applying each rule by hand to this sentence gives these counts:
| Method | Tokens produced | Count |
| Split on whitespace | Don't / over-edit: / the / draft—about / 3 / pages—is / fine. | 7 |
| Pattern \b\w+\b (runs of letters and digits) | Don / t / over / edit / the / draft / about / 3 / pages / is / fine | 11 |
| Pattern \w+(?:['’-]\w+)* (keeps contractions and hyphenated words together) | Don't / over-edit / the / draft / about / 3 / pages / is / fine | 9 |
Whitespace splitting undercounts here because the em dashes join words without spaces. The simple letter-run pattern overcounts because it breaks the contraction and the hyphenated word apart. The third pattern treats apostrophes and hyphens inside a word as part of it, while still separating words joined by em dashes. None of these is universally correct; pick the one that matches the rule you are being measured against, or the one closest to how a reader would count.
Other features of real articles that commonly shift the total:
- Numbers such as 3 or 2.5 count as words under both approaches described here, though a pattern-based counter may split 2.5 into two tokens at the decimal point.
- URLs and email addresses usually count as one word with whitespace splitting and as several with a letter-run pattern.
- Markdown or other markup adds tokens: a list marker like - or a heading marker like ## counts as a word under whitespace splitting but is ignored by letter-run patterns.
- Curly apostrophes (’, U+2019) and straight apostrophes (') are different characters, so a pattern must include both to treat contractions consistently.
- Invisible characters matter. A non-breaking space (U+00A0) looks like a space but may or may not be treated as one, depending on the tool. A zero-width space (U+200B) is invisible yet can split or join words unexpectedly.
- Languages written without spaces between words, such as Chinese, Japanese or Thai, cannot be counted meaningfully by whitespace splitting. They need a word segmentation tool for that language, or a character count instead.
How to count words in an article step by step
Prerequisites: the article as plain text, saved in a known encoding (UTF-8 is the usual choice), and a clear rule for which parts of the article are included. The steps below use two widely available options: the wc command on Linux and macOS, and a short Python script.
- 1. Make a copy of the article to work on. Counting does not modify text, but the cleanup in the next step does, and working on a copy keeps the original intact.
- 2. In the copy, remove anything your rule excludes, such as the reference list, captions or front matter. If the source is Markdown or HTML, strip the markup or export the document as plain text.
- 3. Save the copy as plain text in UTF-8, for example as article.txt.
- 4. Run a whitespace-based count.
- 5. Run a pattern-based count.
- 6. Compare the two results and investigate any large gap before reporting a number.
For a whitespace-based count, the standard wc command with the -w option counts sequences of characters separated by whitespace:
wc -w article.txt
How wc handles non-ASCII characters and non-breaking spaces can depend on the implementation and on your locale settings, so treat its result as a whitespace count under your system's rules. Line endings do not change the result: Windows-style CRLF and Unix-style LF line breaks are both whitespace.
For more control, the following Python script reads the file as UTF-8 and reports both counts. The pattern is the contraction- and hyphen-aware one from the table above; \u2019 is the curly apostrophe written as an escape so the script stays plain ASCII.
import re
with open("article.txt", encoding="utf-8") as f:
text = f.read()
whitespace_count = len(text.split())
word_pattern = re.compile(r"\w+(?:['\u2019-]\w+)*")
pattern_count = len(word_pattern.findall(text))
print("whitespace:", whitespace_count)
print("pattern:", pattern_count)
In Python 3, str.split() with no arguments splits on any character Python classifies as whitespace, which includes the non-breaking space but not the zero-width space. In the pattern, \w matches Unicode letters, digits and the underscore by default, so accented words such as café count as single words.
How to check the result
- Hand-check a sample: copy one paragraph into its own file, count its words by hand using your chosen rule, then run the same method on that file. The numbers should match.
- Inspect the tokens: if the two methods disagree noticeably, print the tokens with print(text.split()) or print(word_pattern.findall(text)) and look for leftover markup, joined words or split contractions.
- Look for invisible characters: print([t for t in text.split() if not t.isascii()]) lists tokens containing non-ASCII characters, which is where non-breaking spaces, zero-width spaces and curly quotes show up. Printing a suspicious token with repr() reveals escapes such as \xa0 or \u200b.
- Confirm the scope: make sure excluded sections were actually removed from the copy, and that nothing you meant to keep was deleted.
If an online word counter or a word processor gives a different total from your own count, the difference almost always comes from tokenization or scope. The material behind this guide did not include documentation for specific online counters or word processors, so their exact rules for hyphens, numbers, URLs and invisible characters are not described here. When a limit is enforced by a particular tool, run the sample sentence above through that tool and compare its result with the table to see which rule it follows.