The reason a
and b
are included in the second case is because (?<=[a-z]\))
would first find a)
and since lookaround's don't consume any character you are back at the start of string.Now [^.)]+
matches a
Now you are at )
.Since you have made (?<=[a-z]\))
optional [^.)]+
matches xyz
This same thing is repeated with b) abc
remove ?
from the second case and you would get the expected result i.e ['xyz', 'abc']