Quick Start
Tutorial
Search & Replace
Tools & Languages
Examples
Reference
Regex Reference
Introduction
Table of Contents
Quick Reference
Characters
Basic Features
Character Classes
Shorthands
Anchors
Word Boundaries
Quantifiers
Capturing Groups & Backreferences
Named Groups & Backreferences
Special Groups
Unicode Characters and Properties
Unicode Versions
Unicode Categories
Unicode Scripts
Unicode Blocks
Unicode Binary Properties
Unicode Property Sets
Unicode Boundaries
Mode Modifiers
Recursion & Balancing Groups
Backtracking Control Verbs
Replacement Reference
Characters
Matched Text & Backreferences
Case Conversion
Context
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 Python JavaScript VBScript XRegExp .NET Java ICU RE2 Perl PCRE PCRE2 PHP Delphi R Ruby std::regex Boost Tcl POSIX GNU 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 Unicode3.0 Unicode
2.4 ASCII
ASCIIASCIIASCIInon‑ECMA UnicodeASCIIUnicodedefault ASCIIUnicodeASCIIASCIIUnicodeASCIIASCII1.9 Unicode
1.8 ASCII
ECMA ASCIIECMA
extended
egrep
awk
Unicode
nonoASCIInonono
Word non-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 Unicode3.0 Unicode
2.4 ASCII
ASCIIASCIIASCIInon‑ECMA UnicodeASCIIUnicodedefault ASCIIUnicodeASCIIASCIIUnicodeASCIIASCII1.9 Unicode
1.8 ASCII
ECMA ASCIIECMA
extended
egrep
awk
Unicode
nonoASCIInonono
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 UnicodenononononononononononononononononoUnicodenonononono
Tcl word non-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 UnicodenononononononononononononononononoUnicodenonononono
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 UnicodenononononononononononononononononoUnicodenonononono
Tcl end-of-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 UnicodenononononononononononononononononoUnicodenonononono
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 nononononononononononononononononoECMA
extended
egrep
awk
Unicode
nonoASCIInonono
GNU end-of-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 nononononononononononononononononoECMA
extended
egrep
awk
Unicode
nonoASCIInonono
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 nononononononononono8.34 ASCIIASCII5.5.10 UnicodeXE7 ASCII3.0.3 ASCIInonoUnicodeUnicodeASCIInononono
POSIX end-of-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 nononononononononono8.34 ASCIIASCII5.5.10 UnicodeXE7 ASCII3.0.3 ASCIInonoUnicodeUnicodeASCIInononono
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 nonononononononononononononononononoYESnoYESnonono
UAX 29 word boundary \b and \B Matches at a word boundary ÷ and \B matches at a word non-boundary × according to Unicode Standard Annex #29. (?w)\b.\b matches ! because the WB1 and WB2 rules in UAX 29 treat the start and end of the string as a word boundary. nononononononooptionnonononononononononon/an/anon/an/an/a
UAX 29 word boundary \b{wb} Matches at a word boundary ÷ according to Unicode Standard Annex #29. \b{wb}.\b{wb} matches ! because the WB1 and WB2 rules in UAX 29 treat the start and end of the string as a word boundary. nonononononononono5.22nononononononononononononono
UAX 29 word non-boundary \b{wb} Matches at a word non-boundary × according to Unicode Standard Annex #29. \B{wb}'\B{wb} matches ' in John's because the WB6 and WB7 rules in UAX 29 treat the positions before and after a hyphen between two letters as a word non-boundary. nonononononononono5.22nononononononononononononono
FeatureSyntaxDescriptionExampleJGsoft Python JavaScript VBScript XRegExp .NET Java ICU RE2 Perl PCRE PCRE2 PHP Delphi R Ruby std::regex Boost Tcl POSIX GNU Oracle XML XPath

Ad-Free Access and Printable PDF Download

If you find the content on this website helpful they you may want a copy you can read offline or even print, or browse the site as often as you want without ads. You can purchase your own copy of the Regular-Expressions.info printable PDF download. As a bonus, you'll get a lifetime of advertisement-free access to this site!