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: Shorthand Character Classes

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
Shorthand Any shorthand outside character classes Shorthands can be used outside character classes. \w matches a single word character YESYESYESYESYESYESYESYESYESYESYESYESYESYESECMAECMA
extended
egrep
awk
YESn/an/aYESYES10gR2YESYES
Shorthand Any shorthand inside a character class Shorthands can be used inside character classes. [\w] matches a single word character YESYESYESYESYESYESYESYESYESYESYESYESYESYESECMAYESYESn/an/anononoYESYES
Shorthand Any negated shorthand inside a character class Negated shorthands can be used inside character classes. [\W] matches a single character that is not a word character YESYESYESYESYESYESYESYESYESYESYESYESYESYESECMAYESerrorn/an/anononoYESYES
Shorthand \d Adds all digits to the character class. Matches a single digit if used outside character classes. [\d] and/or \d match a character that is a digit Unicodenon‑ECMA UnicodeASCIIUnicodeASCIIASCII5.3.4 Unicode
5.0.0 ASCII
ASCIIASCIIASCIIASCIIASCII3.0 Unicode
2.4 ASCII
ASCIIECMA UnicodeUnicodeUnicodenononono10gR2 UnicodeUnicodeUnicode
Shorthand \w Adds all word characters to the character class. Matches a single word character if used outside character classes. [\w] and/or \w match any single word character Unicodenon‑ECMA UnicodeASCIIUnicodeASCIIASCII5.3.4 Unicode
5.0.0 code page
ASCIIASCIIASCIIASCIIASCII3.0 Unicode
2.4 ASCII
ASCIIECMA UnicodeUnicodeUnicodenonoASCIIASCII10gR2 UnicodeUnicodeUnicode
Shorthand \s Adds all whitespace to the character class. Matches a single whitespace character if used outside character classes. [\s] and/or \s match any single whitespace character Unicodenon‑ECMA UnicodeASCIIUnicodeASCIIASCII5.3.4 Unicode
5.0.0 code page
ASCIIASCIIUnicodeASCIIUnicode3.0 Unicode
2.4 ASCII
ASCIIECMA UnicodeUnicodeUnicodenonoASCIIASCII10gR2 UnicodeASCIIASCII
Shorthand \l and \u Adds all lowercase letters or all uppercase letters to the character class. Matches a single lowercase or uppercase letter if used outside character classes. \u\l matches Aa but not aA. V2 UnicodenonononononononononononononoUnicodenononononononono
Shorthand \v Adds all vertical whitespace to the character class. Matches a single vertical whitespace character if used outside character classes. [\v] and/or \v match any single vertical whitespace character V2 Unicodeno8 Unicode5.10 Unicode7.2 UnicodeUnicode5.2.4 UnicodeUnicodeUnicodenonononononoECMA
1.42–1.85 Unicode
nononononononono
Shorthand \h Adds all horizontal whitespace to the character class. Matches a single horizontal whitespace character if used outside character classes. [\h] and/or \h match any single horizontal whitespace character V2 Unicodeno8 Unicode5.10 Unicode7.2 UnicodeUnicode5.2.4 UnicodeUnicodeUnicodenononononono1.42–1.85
Unicode
nononononononono
Shorthand \h Adds all hexadecimal digits to the character class. Matches a hexadecimal digit if used outside character classes. [\h] and/or \h match any single hexadecimal digit nonononononononononononono1.9 ASCIInononononononononono
XML Shorthand \i Adds all characters that are allowed as the initial character in XML names to the character class. Matches one such character if used outside character classes. \i\c* matches an XML name V2nononononononononononononononononononononoYESYES
XML Shorthand \c Adds all characters that are allowed as the second and following characters in XML names to the character class. Matches one such character if used outside character classes. \i\c* matches an XML name V2nononononononononononononononononononononoYESYES
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