in reply to Re: greedy search
in thread greedy search

Searches are greedy by default. But one situation where you want a non-greedy search that is fairly common is finding the contents of an HTML tag.

Let's say you have:

<a href="?"><b>Hello</b></a>

If you pattern match using /<(.+)>/ your match will contain "a href="?"><b>Hello</b></a".

If you pattern match using /<(.+?)>/ your match will contain "a href="?"", which is usually what people are looking for.

Having the option is great, more power in your hands to find what you want!