Backslash escapes one metacharacter |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
\Q...\E escapes a string of metacharacters |
YES |
NO |
Java 6 |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\x00 through \xFF (ASCII character) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\n (LF), \r (CR) and \t (tab)
|
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
YES |
YES |
\f (form feed) and \v (vtab) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\a (bell) |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\e (escape) |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\b (backspace) and \B (backslash) |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\cA through \cZ (control character) |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\ca through \cz (control character) |
YES |
YES |
NO |
YES |
YES |
YES |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
|
Character
Classes (=Sets)
|
|
[abc] (character class) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
[^abc] (negated character class) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
[a-z] (character class range) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
Hyphen in [\d-z] is a literal |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
Hyphen in [a-\d] is a literal |
YES |
NO |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
Backslash escapes one character class metacharacter |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
YES |
YES |
\Q...\E escapes a string of character class metacharacters |
YES |
NO |
Java 6 |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\d (shorthand for digits) |
YES |
YES |
ascii |
YES |
ascii |
ascii |
option |
ascii |
YES |
NO |
NO |
NO |
NO |
YES |
YES |
\w (shorthand for word characters) |
YES |
YES |
ascii |
YES |
ascii |
ascii |
option |
ascii |
YES |
NO |
NO |
YES |
YES |
YES |
YES |
\s (shorthand for whitespace) |
YES |
YES |
ascii |
YES |
ascii |
YES |
option |
ascii |
YES |
NO |
NO |
YES |
YES |
ascii |
ascii |
\D, \W and \S
(shorthand negated character classes)
|
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
YES |
YES |
YES |
YES |
[\b] (backspace) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
|
Dot
and Anchors
|
|
. (dot; any character except line break) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
^ (start of string/line) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
$ (end of string/line) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
\A (start of string) |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\Z (end of string, before final line break) |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\z (end of string) |
YES |
YES |
YES |
YES |
YES |
NO |
\Z |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\` (start of string) |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
YES |
NO |
NO |
\' (end of string) |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
YES |
NO |
NO |
|
Word
Boundaries
|
|
\b (at the beginning or end of a word) |
YES |
YES |
YES |
YES |
ascii |
ascii |
option |
ascii |
NO |
NO |
NO |
YES |
YES |
NO |
NO |
\B (NOT at the beginning or end of a word) |
YES |
YES |
YES |
YES |
ascii |
ascii |
option |
ascii |
NO |
NO |
NO |
YES |
YES |
NO |
NO |
\y (at the beginning or end of a word) |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\Y (NOT at the beginning or end of a word) |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\m (at the beginning of a word) |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\M (at the end of a word) |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\< (at the beginning of a word) |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
YES |
NO |
NO |
\> (at the end of a word) |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
YES |
NO |
NO |
|
Alternation and
Quantifiers
|
|
| (alternation) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
\| |
YES |
YES |
YES |
? (0 or 1) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
\? |
YES |
YES |
YES |
* (0 or more) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
+ (1 or more) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
\+ |
YES |
YES |
YES |
{n} (exactly n) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
\{n\} |
YES |
\{n\} |
YES |
YES |
YES |
{n,m} (between n and m) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
\{n,m\} |
YES |
\{n,m\} |
YES |
YES |
YES |
{n,} (n or more) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
\{n\} |
YES |
\{n\} |
YES |
YES |
YES |
? after any of the above quantifiers to make it "lazy"
|
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
YES |
|
Grouping
and Backreferences |
|
(regex) (numbered capturing group) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
\( \) |
YES |
\( \) |
YES |
YES |
YES |
(?:regex) (non-capturing group) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\1 through \9 (backreferences) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
YES |
NO |
YES |
\10 through \99 (backreferences) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
N/A |
NO |
NO |
N/A |
YES |
Forward references \1 through \9 |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
YES |
NO |
NO |
N/A |
NO |
NO |
N/A |
NO |
Nested references \1 through \9 |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
NO |
NO |
N/A |
NO |
NO |
N/A |
NO |
Backreferences non-existent groups are an error |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
NO |
YES |
YES |
N/A |
YES |
YES |
N/A |
YES |
Backreferences to failed groups also fail |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
YES |
YES |
YES |
N/A |
YES |
YES |
N/A |
YES |
\G (start of match attempt)
|
YES |
YES |
YES |
YES |
YES |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
|
Modifiers
|
|
(?i) (case insensitive) |
YES |
YES |
YES |
YES |
YES |
/i only |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
flag |
(?s) (dot matches newlines) |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
(?m) |
NO |
NO |
NO |
NO |
NO |
NO |
flag |
(?m) (^ and $ match
at line breaks)
|
YES |
YES |
YES |
YES |
YES |
/m only |
YES |
always on |
NO |
NO |
NO |
NO |
NO |
NO |
flag |
(?x) (free-spacing mode) |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
flag |
(?n) (explicit capture) |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
(?-ismxn) (turn off mode modifiers) |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
(?ismxn:group) (mode modifiers local to group) |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
|
Atomic Grouping
and
Possessive Quantifiers |
|
(?>regex) (atomic group) |
YES |
YES |
YES |
YES |
YES |
NO |
3.11 |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
?+, *+, ++ and
{m,n}+ (possessive quantifiers)
|
YES |
NO |
YES |
NO |
YES |
NO |
3.11 |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
|
Lookaround
|
|
(?=regex) (positive lookahead) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
(?!regex) (negative lookahead) |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
(?<=text) (positive lookbehind) |
full regex |
full regex |
finite length |
fixed length |
fixed + alternation |
NO |
fixed length |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
(?<!text) (negative lookbehind) |
full regex |
full regex |
finite length |
fixed length |
fixed + alternation |
NO |
fixed length |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
|
Conditionals
|
|
(?(?=regex)then|else) (using any lookaround) |
YES |
YES |
NO |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
(?(regex)then|else) |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
(?(1)then|else) |
YES |
YES |
NO |
YES |
YES |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
(?(group)then|else) |
YES |
YES |
NO |
NO |
YES |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
|
Comments and
Free-Spacing
Syntax
|
|
(?#comment) |
YES |
YES |
NO |
YES |
YES |
NO |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
Free-spacing syntax supported |
YES |
YES |
YES |
YES |
YES |
NO |
YES |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
YES |
Character class is a single token |
YES |
YES |
NO |
YES |
YES |
N/A |
YES |
YES |
YES |
N/A |
N/A |
N/A |
N/A |
N/A |
YES |
# starts a comment |
YES |
YES |
YES |
YES |
YES |
N/A |
YES |
YES |
YES |
N/A |
N/A |
N/A |
N/A |
N/A |
NO |
|
Unicode
Characters
|
|
\X (Unicode grapheme) |
YES |
NO |
NO |
YES |
option |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\u0000 through \uFFFF (Unicode character)
|
YES |
YES |
YES |
NO |
NO |
YES |
3.0 |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
\x{0} through \x{FFFF} (Unicode character)
|
YES |
NO |
NO |
YES |
option |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
|
Unicode
Properties, Scripts, Blocks
|
|
\pL through \pC (Unicode properties) |
YES |
NO |
YES |
YES |
option |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\p{L} through \p{C} (Unicode properties) |
YES |
YES |
YES |
YES |
option |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
YES |
\p{Lu} through \p{Cn} (Unicode property) |
YES |
YES |
YES |
YES |
option |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
YES |
\p{L&} and \p{Letter&} (equivalent of
[\p{Lu}\p{Ll}\p{Lt}] Unicode properties)
|
YES |
NO |
NO |
YES |
option |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\p{IsL} through \p{IsC} (Unicode properties)
|
YES |
NO |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\p{IsLu} through \p{IsCn} (Unicode property)
|
YES |
NO |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\p{Letter} through \p{Other} (Unicode
properties)
|
YES |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\p{Lowercase_Letter} through \p{Not_Assigned}
(Unicode property)
|
YES |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\p{IsLetter} through \p{IsOther} (Unicode
properties)
|
YES |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\p{IsLowercase_Letter} through \p{IsNot_Assigned} (Unicode property)
|
YES |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\p{Arabic} through \p{Yi} (Unicode script)
|
YES |
NO |
NO |
YES |
option |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\p{IsArabic} through \p{IsYi} (Unicode
script)
|
YES |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\p{BasicLatin} through \p{Specials} (Unicode
block)
|
YES |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\p{InBasicLatin} through \p{InSpecials}
(Unicode block)
|
YES |
NO |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\p{IsBasicLatin} through \p{IsSpecials}
(Unicode block)
|
YES |
YES |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
YES |
Part between {} in all of the above is case insensitive
|
YES |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
Spaces, hyphens and underscores allowed in all long names listed above (e.g.
"BasicLatin" can be
written as "Basic-Latin" or "Basic_Latin" or "Basic Latin")
|
YES |
NO |
Java 5 |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\P (negated variants of all \p as listed
above)
|
YES |
YES |
YES |
YES |
option |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
YES |
\p{^...} (negated variants of all \p{...} as
listed above)
|
YES |
NO |
NO |
YES |
option |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
|
Named
Capture and Backreferences |
|
(?<name>regex) (.NET-style named capturing group) |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
(?'name'regex) (.NET-style named capturing group) |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\k<name> (.NET-style named backreference) |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\k'name' (.NET-style named backreference) |
YES |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
(?P<name>regex) (Python-style named capturing group) |
YES |
NO |
NO |
NO |
YES |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
(?P=name) (Python-style named backreference) |
YES |
NO |
NO |
NO |
YES |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
Multiple capturing groups can have the same name |
YES |
YES |
N/A |
N/A |
NO |
N/A |
NO |
N/A |
N/A |
N/A |
N/A |
N/A |
N/A |
N/A |
N/A |
|
XML
Character Classes |
|
\i, \I, \c and
\C (shorthand XML name character classes)
|
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
YES |
[abc-[abc]] (character class subtraction) |
YES |
2.0 |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
YES |
|
POSIX
Bracket Expressions |
|
[:alpha:] (POSIX character class) |
YES |
NO |
NO |
YES |
ascii |
NO |
NO |
YES |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
\p{Alpha} (POSIX character class) |
YES |
NO |
ascii |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
\p{IsAlpha} (POSIX character class) |
YES |
NO |
NO |
YES |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
[.span-ll.] (POSIX collation sequence) |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
YES |
YES |
YES |
YES |
NO |
NO |
[=x=] (POSIX character equivalence) |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
NO |
YES |
YES |
YES |
YES |
YES |
NO |
NO |