1, Greediness (Greedy type):Maximum Match
X, x*, x+, X{n,} are allmaximum match. For example you want to use "<.+>" to Match "A<tr>aava</tr>abb", perhaps the result you expect is to match "<tr>", but the actual result will be matched to "<tr>aava</ Tr> ". What is this for? Below we track the matching process for the maximum match.
① "<" matches the string "<". ② ". +" matches the string "Tr>aava</tr>ab", when the maximum match, it matches two ">", it matches all characters until the last character of the text "B" ③ at this time, found that cannot successfully match ">", began to follow the original path fallback, with "A" matches ">" until ">" in front of "AB" is successfully matched.
2, reluctant (laziness)(barely type): minimum Match
X, x*, x+, X{n,} are the maximum matches. All right, add one? It becomes a laziness match. For example X??、 x*, x+, X{n,}? are the minimum matches, in fact x{n,m}? and X{n}? Some superfluous.
Minimum matching means,. +? After matching a character, try the > match immediately and fail, then. +? Match one character, then try > match at once. JDK document greedy and reluctant, it is eat a mouthful to metaphor, so translated into greedy and (reluctantly) anorexia most appropriate. But I like the idea of the biggest match and the smallest match.
3, possessive (possessive type): exact match
Unlike the maximum match, there is also a matching form: x?+, x*+, x + +, x{n,}+, and so on, becoming an exact match. It matches all characters until the end of the text, but it is not returned by the original path, as with the maximum match. In other words, a match, can not make it even, to also simply, I like.
Java Regular Expression quantifier---three matching patterns "greedy, reluctant, possessive"