I was practicing regular expressions of java in the tutorial of Oracle. In order to understand greedy, reluctant, and possessive quantifiers better, I created some examples. My question is how those quantifiers work while capturing groups. I didn't understand using quantifiers in that manner, for example, reluctant quantifier looks as if it doesn't work at all. Also, I searched a lot in the Internet and only saw expressions like (.*?). Is there a reason why people usually use quantifiers with that syntax, not something like "(.foo)??"?
Here is the reluctant example:
Enter your regex: (.foo)??
Enter input string to search: xfooxxxxxxfoo
I found the text "" starting at index 0 and ending at index 0.
I found the text "" starting at index 1 and ending at index 1.
I found the text "" starting at index 2 and ending at index 2.
I found the text "" starting at index 3 and ending at index 3.
I found the text "" starting at index 4 and ending at index 4.
I found the text "" starting at index 5 and ending at index 5.
I found the text "" starting at index 6 and ending at index 6.
I found the text "" starting at index 7 and ending at index 7.
I found the text "" starting at index 8 and ending at index 8.
I found the text "" starting at index 9 and ending at index 9.
I found the text "" starting at index 10 and ending at index 10.
I found the text "" starting at index 11 and ending at index 11.
I found the text "" starting at index 12 and ending at index 12.
I found the text "" starting at index 13 and ending at index 13.
For reluctant, shouldn't it show "xfoo" for index 0 and 4 ? And here is the possessive one:
Enter your regex: (.foo)?+
Enter input string to search: afooxxxxxxfoo
I found the text "afoo" starting at index 0 and ending at index 4
I found the text "" starting at index 4 and ending at index 4.
I found the text "" starting at index 5 and ending at index 5.
I found the text "" starting at index 6 and ending at index 6.
I found the text "" starting at index 7 and ending at index 7.
I found the text "" starting at index 8 and ending at index 8.
I found the text "xfoo" starting at index 9 and ending at index 13.
I found the text "" starting at index 13 and ending at index 13.
And for possessive, shouldn't it try the input only for one time ? I'm really confused especially by this one because of trying every possibility.
Thanks in advance !