How does the ? make a quantifier lazy in regex
- by Uriel Katz
I've been looking into regex lately and figured that the ? operator makes the *,+, or ? lazy. My question is how does it do that?
Is it that *? for example is a special operator, or does the ? have an effect on the *? In other words, does regex recognize *? as one operator in itself, or does regex recognize *? as the two separate operators * and ??
If it is the case that *? is being recognized as two separate operators, how does the ? affect the * to make it lazy. If ? means that the * is optional, shouldn't this mean that the * doesn't have to exists at all. If so, then in a statement .*? wouldn't regex just match separate letters and the whole string instead of the shorter string?
Please explain, I'm desperate to understand.