Let’s say you want to match all href values in <a> tags in an HTML document. You might do something like
But that doesn’t work because the * is greedy and gets everything up until that last closing bracket on the first line. To fix this, make the * lazy but adding a question mark (?) after it.
Notice now that we correctly get 3 matches instead of 2.