推荐答案
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
?
ptional (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
anchor |
matches |
flavors |
^ |
Start of string |
Common* |
^ |
Start of line |
Commonm |
$ |
End of line |
Commonm |
$ |
End of text |
Common* |
$ |
The very end of string |
phpD , javascript |
\A |
Start of string |
Common except js |
\Z |
End of text |
Common except js python |
\Z |
The very end of string |
python |
\z |
The very end of string |
Common except js python |
\b |
Word boundary |
Common |
\B |
Not a word boundary |
Common |
\G |
End of previous match |
Common except js, python re |
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) |
Powered by Discuz! X3.4 |