I was reviewing a test and noticed that a possessive quantifier actually worked in an str.split()
. so I wrote the following code:
String str = "aaaaab";
if(str.matches("a*+b"))
System.out.println("I backtrack");
else
System.out.println("Nope.");
When run, this prints out I backtrack
. Here's why this is confusing, I've been told that a possessive quantifier never backtracks, so why would a*+
give up the b
in the String?
What I want is a more detailed explanation of when possessive quantifiers backtrack.