I know what * is and what ? is.
However, I don’t understand what *? is. I know it’s used to make the “greedy” * operator a lazy one, but still, how does that read if * is zero or more times and ? is one or one time.
Thank you.
EDIT:
I underline the fact that I know what *, ?, greedy and lazy are.
This is a trick that has been used to extend regexp syntax without adding more special characters. Of course saying “zero or one” after “zero or more” has no meaning… so the combination
*?should be read as a single token meaning “zero or more – not greedy”. In a similar way+?should be read as a single token meaning “one or more – not greedy”.Greedyness never changes what strings are matched and what are not matched, but it may change what is the match found. For example group 1 of
(AB*?)B+matchesAinABBBBB, but group 1 of(AB*)B+matchesABBBBin the same string.The question mark in “strange places” has been used also in other special combinations that are available in several regexp engines, for example:
as you see they all start with
(?where clearly the question mark couldn’t mean “zero or one” (we’re at the beginning of an expression, zero or one of what?).