Word segmentation and the Word Break problem
What the Word Break problem asks, how word segmentation changes stored text, and when segmented output stays readable, searchable and safe to share.
"Word break" can mean several things. It can mean a classic dynamic programming exercise, a natural-language step that splits running text into words, a Unicode rule for finding word boundaries, or a CSS property that controls line wrapping. These differ in what they actually change. Some rewrite the characters you store, and some only change how text looks on screen. This review explains each meaning so you can judge whether a segmentation step keeps the meaning, readability and usability your task needs.
Is word segmentation suitable for your use?
Segmenting text into words is worth doing when a later step needs word units. Examples include search indexing, tokenization for analysis, hashtag or URL-slug splitting, spell checking, and languages written without spaces between words. Its main benefit is that it gives software boundaries it can count, match and process.
The key tradeoff is that segmentation is an interpretation, not a lossless operation. A single string can have more than one valid split. The chosen split depends on the dictionary or model, and inserting spaces changes the stored text. If the split is wrong, the meaning can change, and later steps inherit that error.
Keep the original plain text when any of these apply:
• The text is a name, identifier, password, code or product key, where any change breaks it.
• Exact matching or legal or archival fidelity matters.
• You only need nicer line wrapping on screen, which is a display problem rather than a text problem.
• You cannot review ambiguous splits.
A practical rule is to store the original and treat any segmented version as derived data.
What the Word Break problem asks
In its common practice form, the Word Break problem gives you a string with no spaces and a dictionary of words. You must decide whether the string can be split into a sequence of dictionary words, and words may be reused. A second variant, often called Word Break II, asks for every possible sentence instead of a yes or no answer. Coding practice sites present it as a standard dynamic programming exercise.
| Input string | Dictionary | Result |
| applepenapple | apple, pen | Yes: apple pen apple |
| catsandog | cats, dog, sand, and, cat | No: every split leaves an unmatched remainder (cat sand og, cats and og) |
| catsanddog | cats, dog, sand, and, cat | Yes, two ways: cat sand dog and cats and dog |
The last row shows why segmentation is ambiguous. Both sentences are valid, and only context or a ranking model can say which one the writer meant. The yes/no version hides this ambiguity. The all-solutions version exposes it, and the number of results can grow very quickly for repetitive inputs.
A standard dynamic programming solution
The usual approach records, for each position in the string, whether the prefix ending there can be fully segmented. A position is reachable if some earlier reachable position is followed by a dictionary word that ends exactly here. Limiting the inner loop to the longest dictionary word avoids checking substrings that cannot match.
def word_break(s, words):
vocab = set(words)
max_len = max((len(w) for w in vocab), default=0)
ok = [False] * (len(s) + 1)
ok[0] = True # empty prefix is always segmentable
for end in range(1, len(s) + 1):
for start in range(max(0, end - max_len), end):
if ok[start] and s[start:end] in vocab:
ok[end] = True
break
return ok[len(s)]
The function only answers whether a segmentation exists. To recover an actual split, store which start position made each end reachable and walk backward from the end. For all splits, use memoized recursion. Be aware that listing every result can be exponential in output size even when the yes/no check is fast.
What segmentation actually changes
Different features called "word break" act on different layers. The key distinction is whether the stored characters change or only their on-screen presentation does.
| Meaning | What it changes | Stored characters altered? |
| Word Break problem (algorithm) | Nothing by itself; it returns a yes/no answer or a list of candidate splits | No, unless you write a chosen split back |
| Word segmentation output | Inserts separators, usually spaces, between detected words | Yes |
| Unicode word boundary rules | Define where boundaries fall for cursor movement, selection and tokenization | No; they only report positions |
| CSS word-break and related properties | Control where a line may wrap when text is displayed | No; display only |
| Inserted zero-width space | Adds an invisible character that marks a break opportunity | Yes, even though nothing visible changes |
Segmentation is also separate from reversal, mirroring and decorative "font" substitution. Those features reorder characters, change glyph appearance or swap in look-alike Unicode symbols. Segmentation leaves every original character in place and in order, and only adds separators. That makes it easier to undo than character substitution, as long as you know which separators were added.
Working on characters, not bytes or code units
Textbook solutions index the string one position at a time. That works for plain ASCII. In real text, one visible character can be several code points: a letter followed by a combining accent, or an emoji built from several code points joined together. A segmenter that splits between those pieces can separate an accent from its letter or break an emoji into fragments. Real-world segmenters should place boundaries only between whole user-perceived characters, and dictionary entries should be normalized the same way as the input. Otherwise, visually identical words may fail to match.
Languages without spaces
Some languages, such as Chinese, Japanese and Thai, are commonly written without spaces between words. Generic Unicode boundary rules do not determine words in these scripts on their own, so production text libraries typically add dictionaries or statistical models. This is the Word Break problem at full scale. The dictionary is large and incomplete, several splits are valid, and the best one has to be ranked rather than merely found. Accuracy depends on the specific tool and its data. No measurements for any particular segmenter were available for this review.
Does segmented text stay readable and usable after copying or sharing?
Copying text carries whatever the stored characters are. If segmentation inserted ordinary spaces, those spaces travel with the text. Every destination will show them, and searches for the original unbroken string will no longer match. Display-only wrapping, such as CSS word-break, is not copied. Pasting brings back the original characters, and the line breaks you saw disappear.
Invisible separators carry the most risk. A zero-width space looks like nothing, but it is a real character. It can make two strings that look the same compare as different, break exact-match search, interfere with editing, and end up in identifiers or links. If you used invisible separators, make that clear and provide a version without them.
For accessibility, screen readers and text-to-speech tools generally rely on word boundaries to decide what to pronounce. A wrong split can change how a phrase is read aloud or what it appears to mean. How any specific screen reader handles inserted spaces or zero-width characters was not tested for this review. Check the assistive technology and destinations you actually target rather than assuming one good rendering applies everywhere.
- When to keep or provide a plain-text equivalent:
- Always keep the unsegmented original alongside any derived version.
- Provide the original wherever exact matching, copying into forms, or identifiers are involved.
- Strip invisible separators before sharing outside the system that needed them.
- Have a person review ambiguous splits before the segmented text is shown to readers as final wording.
Gaps in this review
No specific segmentation product, accuracy figure, performance measurement or destination test was available. This article therefore covers the general mechanism, the standard algorithm and documented distinctions between text and presentation. It does not rank tools or make claims about how a particular app, platform or screen reader handles segmented output. Before relying on segmentation in a live workflow, test with representative input, including accented text, emoji and any languages written without spaces.