See also a lot of general hints and useful links at the regex tag details page.
Online tutorials
Quantifiers
*
:greedy, *?
:reluctant, *+
:possessive+
:greedy, +?
:reluctant, ++
:possessive?
:optional (zero-or-one){n,m}
:between n & m, {n,}
:n-or-more, {n}
:exactly n{n}
and {n}?
Character Classes
[...]
: any one character, [^...]
: negated/any character but[^]
matches any one character including newlines javascript[w-[d]]
/ [a-z-[qz]]
: set subtraction .net, xml-schema, xpath, JGSoft[w&&[^d]]
: set intersection java, ruby 1.9+[[:alpha:]]
:POSIX character classes[^\D2]
, [^[^0-9]2]
, [^2[^0-9]]
get different results in Java? javad
:digit, D
:non-digitw
:word character, W
:non-word characters
:whitespace, S
:non-whitespacep{L}, P{L}
, etc.)Escape Sequences
h
:space-or-tab,
:tabH
:Non horizontal whitespace character, V
:Non vertical whitespace character, N
:Non line feed character pcre php5 java-8v
:vertical tab, e
:the escape characterAnchors
^
:start of line/input,
:word boundary, and B
:non-word boundary, $
:end of line/inputA
:start of input,
:end of input php, perl, rubyz
:the very end of input (
in Python) .net, php, pcre, java, ruby, icu, swift, objective-cG
:start of match php, perl, ruby(Also see "Flavor-Specific Information → Java → The functions in Matcher
")
Groups
(...)
:capture group, (?:)
:non-capture group
1
:backreference and capture-group reference, $1
:capture group reference
(?i:regex)
mean?(?P<group_name>regexp)
mean?(?>)
:atomic group or independent group, (?|)
:branch reset
regular-expressions.info
(?<groupname>regex)
: Overview and <a href="https://d