0

I was reading about quantifiers on the documentations page of oracle on this link

https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html

Greedy quantifiers
X?  X, once or not at all
X*  X, zero or more times
X+  X, one or more times
X{n}    X, exactly n times
X{n,}   X, at least n times
X{n,m}  X, at least n but not more than m times

Reluctant quantifiers
X??     X, once or not at all
X*?     X, zero or more times
X+?     X, one or more times
X{n}?   X, exactly n times
X{n,}?  X, at least n times
X{n,m}?     X, at least n but not more than m times

Possessive quantifiers
X?+     X, once or not at all
X*+     X, zero or more times
X++     X, one or more times
X{n}+   X, exactly n times
X{n,}+  X, at least n times
X{n,m}+     X, at least n but not more than m times

I am not able to comprehend why the matches are same for each of these things? Even if they are divided in different groups.

I even tried running them and was getting exactly same thing for each of them.

So the question is Why?

Shad
  • 1,185
  • 1
  • 12
  • 27
  • 1
    These patterns will match the same things **for SOME strings**. Please show us *which* strings you are using to test with. Moreover, what exactly do you need explaining in more detail? – Tom Lord Nov 28 '17 at 14:10
  • You probably constructed an example where greedy vs. reluctant vs. possessive did not matter. Please show the strings you tried to match, and the matches that you've got. – Sergey Kalinichenko Nov 28 '17 at 14:10
  • Just simple, like a*?, a?+ – Shad Nov 28 '17 at 14:22

0 Answers0