Greediness: Maximum match
X?, X*, X+, X{n,} is the largest match. For example, if you want to use "<.+>" to match "a<tr>aava </tr>abb", maybe the result you are expecting is to match "<tr>", but the actual result will match "<tr>aava </tr>.
In Greediness mode, the match will be as large as possible until the entire content is matched. When it is found that the match cannot be successful, the match will begin to fall back and narrow the match range until the match is successful.
String test = "a<tr>aava </tr>abb "; String reg = "<.+>"; ((reg, "###"));
Output: a###abb
Reluctant(Laziness) (barely type): minimum matching
X??, X*?, X+?, X{n,}? are the smallest matches, but in fact X{n, m}? and X{n}? are somewhat redundant. Adding ? after Greediness mode becomes the minimum match.
In Reluctant mode, as long as the match is successful, no longer try to match a larger range of content
String test = "a<tr>aava </tr>abb "; String reg = "<.+?>"; ((reg, "###"));
Output: a###aava ###abb
Unlike Greediness, the content matches twice in Reluctant mode
Possessive: Exact match
X?+, X*+, X++, X{n,}+ are exact matches, and adding + after the Greediness pattern becomes an exact match.
The Possessive pattern has a certain similarity to Greediness, that is, they all try to match the maximum range of content until the content ends, but unlike Greediness, the exact match does not fall back and try to match the smaller range.
String test = "a<tr>aava </tr>abb "; String reg = "<.++>"; String test2 = "<tr>"; String reg2 = "<tr>"; ((reg, "###")); ((reg2, "###"));
Output: a<tr>aava </tr>abb