Java J2SE "Regular Expressions" Cheat Sheet V 0.1
Java J2SE "Regular Expressions" Cheat Sheet V 0.1
1
Metacharacters
([{\^$|)?*+.
Character Classes
[abc]
a, b, or c (simple class)
Any character except a, b, or c (negation)
[^abc]
[a-zA-Z]
[a-d[m-p]]
[a-z&&[def]] d, e, or f (intersection)
a through z, except for b and c: [ad-z] (subtrac[a-z&&[^bc]] tion)
a through z, and not m through p: [a-lq-z] (sub[a-z&&[^m-p]] traction)
.
\d
A digit: [0-9]
\D
A non-digit: [^0-9]
\s
\S
\w
\W
Greedy
X?
X??
X?+
X*
X*?
X*+
X+
X+?
X++
X{n}
X{n}?
X{n}+
X{n,}
X{n,}?
X{n,}+
X{n,m}
X{n,m}?
X{n,m}+
X, exactly n times
X, at least n times
X, at least n but not more than
m times
Boundary Matchers
^
\b
A word boundary
\B
A non-word boundary
\A
\G
\Z
The end of the input but for the final terminator, if any
\z
CANON_EQ
CASE_INSENSITIVE
COMMENTS
DOTALL
MULTILINE
UNICODE_CASE
UNIX_LINES