Quick Start
Tutorial
Tools & Languages
Examples
Reference
Book Reviews
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
RegexBuddy—Better than a regular expression reference!

Regular Expression Reference: Word Boundaries

FeatureSyntaxDescriptionExampleJGsoft .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 UnicodeASCIIUnicodeASCIIASCII5.3.4 Unicode
5.0.0 code page
ASCIIASCIIASCIIASCIIASCII3.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 UnicodeASCIIUnicodeASCIIASCII5.3.4 Unicode
5.0.0 code page
ASCIIASCIIASCIIASCIIASCII3.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 ASCIInonononononoUnicodeUnicodeASCIIASCIInonononono
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 ASCIInonononononoUnicodeUnicodeASCIIASCIInonononono
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
FeatureSyntaxDescriptionExampleJGsoft .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