Greedy vs. Reluctant vs. Possessive Quantifiers

前端 未结 7 1073
傲寒
傲寒 2020-11-21 07:19

I found this excellent tutorial on regular expressions and while I intuitively understand what \"greedy\", \"reluctant\" and \"possessive\" quantifiers do, there seems to be

7条回答
  •  忘掉有多难
    2020-11-21 07:47

    Greedy: "match the longest possible sequence of characters"

    Reluctant: "match the shortest possible sequence of characters"

    Possessive: This is a bit strange as it does NOT (in contrast to greedy and reluctant) try to find a match for the whole regex.

    By the way: No regex pattern matcher implementation will ever use backtracking. All real-life pattern matcher are extremely fast - nearly independent of the complexity of the regular expression!

提交回复
热议问题