Difference between exact greedy/reluctant X{n}?

Viewed 133

In the documentation for the Java Pattern class, I see that the exact quantifier X{n} has both greedy and reluctant forms:

Greedy quantifiers

  • X{n} X, exactly n times
  • ...

Reluctant quantifiers

  • X{n}? X, exactly n times
  • ...

The documentation gives general examples of the difference between greedy and reluctant behavior, but doesn't give any examples for the exact quantifiers.

At first I thought, "Well, maybe the difference is that X itself could match in difference ways." But then X can have its own greedy/reluctant specifiers inside it, and sure enough I tested it and that's not a difference (greedy vs reluctant).

Given that, in either case, it is going to match exactly n times, is there any difference between the behavior of the two?

1 Answers
Related