I just stumbled over a beautiful but not commonly known regexp search solution. Excuse my stupidity, but I felt like a thread about common regexp solutions would encourage users to use them

in many cases you will be discouraged to use the so called "greedy" quantifiers
+ - one or more occurrences
* - zero or more occurrences
example:
you want to search for any opening link HTML tag <a href=link>
The common problem is that you shouldn't write:
<a href=.*>
as it would select the entire text from the first <a href= till the last > character in the entire file.
Many handbooks advise to use some ugly method like
<a href=[^<]*>
where the [^<]* means search zero or more occurrences of any character except < which is sooo ugly

But hey! We have LAZY quantifiers
Code: Select all
Greedy Lazy
* *?
+ +?
{n,} {n,}?
with which you can do it in a snap like this:
<a href=.*?>
Naturally the dot '.' is any character but since you use *? the search will stop by the first occurence of the > character
TRY IT, YOU WON'T REGRET IT!!!

_____________________________________________
...and in that fashion it can get complex:
lets say you want to search for any sequence of tags for HTML table cell
<td any parameters>anything<a href=anything>anything</a>anything</td>
you don't have to perform magic for this one with the lazy quantifiers,
just remember that instead of * (as in non-regexp filters, searches) you should use .*?
so you can imagine it with the 'stars' first just like
<td*>*<a href=*>*</a>*</td>
the seqence in regexp is simple then
<td.*?>.*?<a href=.*?>.*?</a>.*?</td>
Nice!
I've got this from a genious chm help file called SAMS - Teach Yourself Regular Expressions in 10 Minutes - 2004.