How to precisely identify & work greedy or reluctant quantifiers?

This question already has an answer here:

  • SCJP6 regex issue 1 answer

  • These are the matches of d* against "ab34ef" :

  • index 0: zero-width;
  • index 1: zero-width;
  • index 2: "34";
  • index 4: zero-width;
  • index 5: zero-width;
  • index 6: zero-width.
  • This should explain your output. If the quantifier was reluctant, this would be the difference:

  • index 2: zero-width;
  • index 3: zero-width;
  • The reluctant quantifier grabs as little as allowed to make the entire expression match.

    链接地址: http://www.djcxy.com/p/13418.html

    上一篇: 所有格量词如何工作?

    下一篇: 如何准确识别和工作贪婪或不情愿的量词?