The Stack Overflow Regular Expressions FAQ
See also a lot of general hints and useful links at the regex tag details page.
Online tutorials
Quantifiers
- Zero-or-more:
*
:greedy, *?
:reluctant, *+
:possessive
- One-or-more:
+
:greedy, +?
:reluctant, ++
:possessive
?
:optional (zero-or-one)
- Min/max ranges (all inclusive):
{n,m}
:between n & m, {n,}
:n-or-more, {n}
:exactly n
- Differences between greedy, reluctant (a.k.a. "lazy", "ungreedy") and possessive quantifier:
Character Classes
Escape Sequences
Anchors
^
:start of line/input,
:word boundary, and B
:non-word boundary, $
:end of line/input
A
:start of input,
:end of input php, perl, ruby
z
:the very end of input (
in Python) .net, php, pcre, java, ruby, icu, swift, objective-c
G
:start of match php, perl, ruby
(Also see "Flavor-Specific Information → Java → The functions in Matcher
")
Groups
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…