gpt4 book ai didi

regex - 有人可以向我解释占有量词吗? (常用表达)

转载 作者:行者123 更新时间:2023-12-03 20:48:19 24 4
gpt4 key购买 nike

我正在阅读 PCRE 文档,它指的是所有格量词,但没有明确或具体地定义它们。我知道什么是贪婪量词,我知道什么是惰性量词。但占有欲?

PCRE man page当它使用该术语而不定义它时,似乎是在作弊。手册页特别指出,所有格量词一词最初是在 Friedl's book 中定义的。 .好吧,那太好了,但我没有 Friedl 的书,在阅读手册页时,在字里行间,我无法弄清楚是什么将所有格量词与贪婪量词区分开来。

  • ? = 零或一,贪婪
  • ?? = 零或一,懒惰
  • ?+ = 零或一,所有格
  • '+' = 一个或多个,贪心
  • +? = 一个或多个,懒惰
  • ++ = 一个或多个,所有格
  • 最佳答案

    也许最好的起点是 Regex Tutorial - Possessive Quantifiers :

    When discussing the repetition operators or quantifiers, I explained the difference between greedy and lazy repetition. Greediness and laziness determine the order in which the regex engine tries the possible permutations of the regex pattern. A greedy quantifier will first try to repeat the token as many times as possible, and gradually give up matches as the engine backtracks to find an overall match. A lazy quantifier will first repeat the token as few times as required, and gradually expand the match as the engine backtracks through the regex to find an overall match.



    Possessive quantifiers are a way to prevent the regex engine from trying all permutations. This is primarily useful for performance reasons. You can also use possessive quantifiers to eliminate certain matches.

    关于regex - 有人可以向我解释占有量词吗? (常用表达),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1117467/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com