liveBook · Manning

Word boundary

As explained in Data-Oriented Programming: Reduce software complexity

A word boundary is a position in text recognized by a regular expression as the boundary between a word character and a non-word character.

A word boundary is a position between a word character and a non-word character. In a regular expression, \b lets a search match a prefix only when that prefix begins a word, rather than matching inside another word. section 15.4

Fixing a multiword search

To support case-insensitive prefix searches, lowercase both strings and build a regular expression from the prefix: new RegExp("\\b" + prefixLowerCase). Thus, \bHabits and \b7 Habits match “7 Habits of Highly Effective People,” while abits does not; \bHabits of also matches. section 15.4

How Data-Oriented Programming: Reduce software complexity covers it

How deep it goes
Defines the boundary and demonstrates matching behavior, then stops short of explaining regular-expression engine internals.
Examples
Tests Habit, habit, 7 Habit, and habits of as matches, while abit, bit, 7 abit, and habit of return no books.
What it assumes
Assumes basic string searching and unit testing, while introducing the \b regular-expression metacharacter from zero.
What you can do after
Apply it via a regular expression to implement and test case-insensitive prefix searches across word boundaries.
How it connects
Connects word boundaries with regular expressions, prefix matching, case-insensitive matching, and unit testing.

Also explained in

Compare how 3 books explain word boundary →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data-Oriented Programming: Reduce software complexity. The section links point to the parts of the book it draws on.