Quick Start
Tutorial
Tools & Languages
Examples
Reference
Book Reviews
RegexBuddy—Better than a regular expression reference!

Regular Expression Reference: Word Boundaries

FeatureSyntaxDescriptionExample JGsoft .NET Java Perl PCRE PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE POSIX BRE POSIX ERE GNU BRE GNU ERE Oracle XML XPath
Word boundary \b Matches at a position that is followed by a word character but not preceded by a word character, or that is preceded by a word character but not followed by a word character. \b. matches a,  , and d in abc def Unicodenon‑ECMA UnicodeUnicodeUnicodeASCIIASCII5.3.4 Unicode
5.0.0 code page
ASCIIcode pageASCIIASCIIASCII3.0 Unicode
2.4 ASCII
UnicodeECMA ASCIIECMA
extended
egrep
awk
Unicode
nononoASCIIASCIInonono
Word boundary \B Matches at a position that is preceded and followed by a word character, or that is not preceded and not followed by a word character. \B. matches b, c, e, and f in abc def Unicodenon‑ECMA UnicodeUnicodeUnicodeASCIIASCII5.3.4 Unicode
5.0.0 code page
ASCIIcode pageASCIIASCIIASCII3.0 Unicode
2.4 ASCII
UnicodeECMA ASCIIECMA
extended
egrep
awk
Unicode
nononoASCIIASCIInonono
Tcl word boundary \y Matches at a position that is followed by a word character but not preceded by a word character, or that is preceded by a word character but not followed by a word character. \y. matches a,  , and d in abc def UnicodenononononononononononononononoUnicodenonononononono
Tcl word boundary \Y Matches at a position that is preceded and followed by a word character, or that is not preceded and not followed by a word character. \Y. matches b, c, e, and f in abc def UnicodenononononononononononononononoUnicodenonononononono
Tcl word boundary \m Matches at a position that is followed by a word character but not preceded by a word character. \m. matches a and d in abc def UnicodenononononononononononononononoUnicodenonononononono
Tcl word boundary \M Matches at a position that is preceded by a word character but not followed by a word character. .\M matches c and f in abc def UnicodenononononononononononononononoUnicodenonononononono
GNU word boundary \< Matches at a position that is followed by a word character but not preceded by a word character. \<. matches a and d in abc def nononononononononononononononoECMA
extended
egrep
awk
Unicode
nononoASCIIASCIInonono
GNU word boundary \> Matches at a position that is preceded by a word character but not followed by a word character. .\> matches c and f in abc def nononononononononononononononoECMA
extended
egrep
awk
Unicode
nononoASCIIASCIInonono
POSIX word boundary [[:<:]] Matches at a position that is followed by a word character but not preceded by a word character. [[:<:]]. matches a and d in abc def nononono8.34 ASCIIASCII5.5.10 UnicodeXE7 ASCII3.0.3 code pagenonononononoUnicodeUnicodeASCIIASCIInonononono
POSIX word boundary [[:>:]] Matches at a position that is preceded by a word character but not followed by a word character. .[[:>:]] matches c and f in abc def nononono8.34 ASCIIASCII5.5.10 UnicodeXE7 ASCII3.0.3 code pagenonononononoUnicodeUnicodeASCIIASCIInonononono
Word boundary behavior Word boundaries always match at the start of the match attempt if that position is followed by a word character, regardless of the character that precedes the start of the match attempt. (Thus word boundaries are not handled correctly for the second and following match attempts in the same string.) \b. matches all of the letters but not the space when iterating over all matches in the string abc def nonononononononononononononononoYESnonoYESYESnonono
FeatureSyntaxDescriptionExample JGsoft .NET Java Perl PCRE PCRE2 PHP Delphi R JavaScript VBScript XRegExp Python Ruby std::regex Boost Tcl ARE POSIX BRE POSIX ERE GNU BRE GNU ERE Oracle XML XPath

Make a Donation

Did this website just save you a trip to the bookstore? Please make a donation to support this site, and you'll get a lifetime of advertisement-free access to this site! Credit cards, PayPal, and Bitcoin gladly accepted.

Regex Reference
Introduction
Table of Contents
Quick Reference
Characters
Basic Features
Character Classes
Shorthands
Anchors
Word Boundaries
Quantifiers
Unicode
Capturing Groups & Backreferences
Named Groups & Backreferences
Special Groups
Mode Modifiers
Recursion & Balancing Groups
Replacement Reference
Characters
Matched Text & Backreferences
Context & Case Conversion
Conditionals
More on This Site
Introduction
Regular Expressions Quick Start
Regular Expressions Tutorial
Replacement Strings Tutorial
Applications and Languages
Regular Expressions Examples
Regular Expressions Reference
Replacement Strings Reference
Book Reviews
Printable PDF
About This Site
RSS Feed & Blog