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

Unless otherwise noted, the syntax on this page is only valid inside character classes, while the syntax on all other reference pages is not valid inside character classes.

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
Character class [ When used outside a character class, [ begins a character class. YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYES
Literal opening bracket [ An opening square bracket is a literal character that adds an opening square bracket to the character class. [ab[cd]ef] matches aef], bef], [ef], cef], and def] YES2.4–3.6YESYESYESYESnonoYESYESYESYESYESYESYESnoYESYESYESYESYESYESnono
Nested character class [ An opening square bracket inside a character class begins a nested character class. [ab[cd]ef] is the same as [abcdef] and matches any letter between a and f. nonononononoYESYESnonononononono1.9nononononononono
Literal character Any character except ^-]\ All characters except the listed special characters are literal characters that add themselves to the character class. [abc] matches a, b or c YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYES
Backslash escapes a metacharacter \ (backslash) followed by any of ^-]\ A backslash escapes special characters to suppress their special meaning. [\^\]] matches ^ or ] YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESECMAECMA
awk
YESnononoYESYES
Literal backslash \ A backslash is a literal character that adds a backslash to the character class. [\] matches \ nonononononononononononononononobasic
extended
grep
egrep
awk
basic
extended
grep
egrep
noYESYESYESnono
Range - (hyphen) between two tokens that each specify a single character. Adds a range of characters to the character class. [a-zA-Z0-9] matches any ASCII letter or digit YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYES
Reversed range Range with the left hand token representing a character with a higher position in the code page than the right hand token. Adds a range of characters to the character class. [z-aZ-A9-0] matches any ASCII letter or digit YESerrorerrorerrorerrorerrorerrorerrorerrorerrorerrorerrorerrorerrorerrorerrorerrorerrorerrorerrorerrorerrorerrorerror
Negated character class ^ (caret) immediately after the opening [ Negates the character class, causing it to match a single character not listed in the character class. [^a-d] matches x (any character except a, b, c or d) YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYES
Character class subtraction [base-[subtract]] Removes all characters in the “subtract” class from the “base” class. [a-z-[aeiuo]] matches a single letter that is not a vowel. YESnononono2.0nonononononononononononononononoYESYES
Character class subtraction [base--[subtract]] Removes all characters in the “subtract” class from the “base” class. [a-z--[aeiuo]] matches a single letter that is not a vowel. no3.7 errornononononoYESnononononononoerrornobasic
extended
grep
egrep
awk
error
nonononoerrorerror
Character class subtraction [base--subtract] Removes all characters in the “subtract” class from the “base” class. [a-z--aeiuo] matches a single letter that is not a vowel. no3.7 errornononononoYESnononononononoerrornobasic
extended
grep
egrep
awk
error
nonononoerrorerror
Character class intersection [base&&[intersect]] Reduces the character class to the characters present in both “base” and “intersect”. [a-z&&[^aeiuo]] matches a single letter that is not a vowel. V2nononononoYESYESnonononononono1.9nononononononono
Character class intersection [base&&intersect] Reduces the character class to the characters present in both “base” and “intersect”. [\p{Nd}&&\p{InThai}] matches a single Thai digit. nonononononoYESYESnonononononono1.9nononononononono
Character escape \n, \r and \t Add an LF character, a CR character, or a tab character to the character class, respectively. [\n\r\t] a line feed, a carriage return, or a tab. YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESECMA
awk
ECMA
awk
YESstringstringnoYESYES
Character escape \a Add the “alert” or “bell” control character (ASCII 0x07) to the character class. [\a\t] matches a bell or a tab character. YESYESnononoYESYESYESYESYESYESYESYESYESYESYESawkECMA
awk
YESnonononono
Character escape \b Add the “backspace” control character (ASCII 0x08) to the character class. [\b\t] matches a backspace or a tab character. YESYESYESYESYESYESnononoYESYESYESYESYESYESYESECMA VC’12–VC’15
awk VC’10–VC’22
ECMA
awk
YESnonononono
Character escape \B Add a backslash to the character class. [\B] matches \ nonononononononononononononononononoYESnonononono
Character escape \e Add the “escape” control character (ASCII 0x1B) to the character class. [\e\t] matches an escape or a tab character. YESnonononoYESYESYESnoYESYESYESYESYESYESYESnoECMA
awk
YESnonononono
Character escape \f Add the “form feed” control character (ASCII 0x0C) to the character class. [\f\t] matches a form feed or a tab character. YESYESYESYESYESYESYESYESYESYESYESYESYESYESYESYESECMA
awk
ECMA
awk
YESnonononono
Character escape \v Add the “vertical tab” control character (ASCII 0x0B) to the character class, without adding any other vertical whitespace. [\v\t] matches a vertical tab or a tab character. V1 onlyYESYESYESYESYES4–7noYESnonononononoYESECMA
awk
ECMA
awk
YESnonononono
POSIX class [:alpha:] Matches one character from a POSIX character class. Can only be used in a bracket expression. [[:digit:][:lower:]] matches one of 0 through 9 or a through z ASCIInonononononoUnicodeASCIIUnicodeASCIIASCIIUnicodeASCIIASCII1.9 Unicode
1.8 ASCII
UnicodeUnicodeUnicodeASCIIASCIIUnicodenono
POSIX class [:^alpha:] Matches one character that is not part of a specific POSIX character class. Can only be used in a bracket expression. [5[:^digit:]] matches the digit 5 or any other character that is not a digit. no3.7 errorwith /u errornonononoYESYESYESYESYESYESYESYES1.9
1.8 error
errorYESerrorerrorerrorerrorerrorerror
POSIX shorthand class [:d:], [:s:], [:w:] Matches one character from the POSIX character classes “digit”, “space”, or “word”. Can only be used in a bracket expression. [[:s:][:d:]] matches a space, a tab, a line break, or one of 0 through 9 V2 ASCIInononononononononononononononoUnicodeUnicodenononononono
POSIX shorthand class [:l:] and [:u:] Matches one character from the POSIX character classes “lower” or “upper”. Can only be used in a bracket expression. [[:u:]][[:l:]] matches Aa but not aA. V2 ASCIInonononononononononononononononoUnicodenononononono
POSIX shorthand class [:h:] Matches one character from the POSIX character classes “blank”. Can only be used in a bracket expression. [[:h:]] matches a space. V2 ASCIInononononononononononononononono1.42
Unicode
nononononono
POSIX shorthand class [:V:] Matches a vertical whitespace character. Can only be used in a bracket expression. [[:v:]] match any single vertical whitespace character. V2 ASCIInononononononononononononononono1.42
Unicode
nononononono
POSIX class Any supported \p{…} syntax \p{…} syntax can be used inside character classes. [\p{Digit}\p{Lower}] matches one of 0 through 9 or a through z YESn/an/an/an/an/a7YESn/aYESn/an/an/an/an/a1.9n/aextended
egrep
n/an/an/an/an/an/a
POSIX class \p{Alpha} Matches one character from a POSIX character class. \p{Digit} matches any single digit. UnicodenononononoASCIIUnicodenoUnicodenonononono1.9 UnicodenoECMA
extended
egrep
awk
Unicode
nononononono
POSIX class \p{IsAlpha} Matches one character from a POSIX character class. \p{IsDigit} matches any single digit. Unicodenonononono7 Unicode
4 ASCII
63 UnicodenoUnicodenononononononononononononono
POSIX collation sequence [.span-ll.] Matches a POSIX collation sequence. Can only be used in a bracket expression. [[.span-ll.]] matches ll in the Spanish locale error3.7 errorwith /u errornonononononoerrorerrorerrorerrorerrorerror1.8 only errorfailYESYESYESYESYESerrorerror
POSIX character equivalence [=x=] Matches a POSIX character equivalence. Can only be used in a bracket expression. [[=e=]] matches e, é, è and ê in the French locale error3.7 errorwith /u errornonononononoerrorerrorerrorerrorerrorerror1.8 only errorYESYESYESYESYESYESerrorerror
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