Yes, the *
operator is greedy, and will capture as many valid characters as it can.
For example, the pattern k(.*)k
applied to kkkkak
will capture kkka
.
You can make an operator non-greedy with the ?
operator.
So the pattern k(.*?)k
applied to kkkkak
will capture nothing, because the smallest non-greedy match is to allow nothing between the first two k
characters.
In reply to your comment, the existance of the final k
in the pattern means that it needs to leave as much as possible to still match a k
after consuming as much as possible.