How does possessive quantifier work?

At the end of the page there is an attempt to explain how greedy, reluctant, and possessive quantifiers work: http://docs.oracle.com/javase/tutorial/essential/regex/quant.html

However, I tried the example itself, and I don't seem to understand it completely.

I will embed my results directly:

Enter your regex: .*+foo
Enter input string to search: xfooxxxxxxfoo
No match found.

Enter your regex: (.*)+foo
Enter input string to search: xfooxxxxxxfoo
I found the text "xfooxxxxxxfoo" starting at index 0 and ending at index 13.

Why the first reg.exp. not find a match, but the second one does? What is the exact difference between these 2 reg.exp.?

+1
source share
2 answers

+ , " regex , ". (. .)

, .*foo "xfooxxxxxxfoo", .* . , foo , regex , , .* "xfooxxxxxx" foo "foo".

+ , .

(.*)+foo. + ; " ". , , , , . , "xfoxxxxxxxxxfox", .

+5

, , . xfooxxxxxxfoo .*+, foo, , .

, "" :

xfooxxxxxxfoo fail
xfooxxxxxxfo fail
xfooxxxxxxf fail
xfooxxxxxx match

- , . " (. *)", + (), .

0

All Articles