The trick is don't use a dot-match-all symbol. Use a regex character class, like
Or match all but tag brackets:
I found this regex tutorial to be very helpful in learning the various fine points of regex:
http://www.regular-expressions.info/
There are some very interesting yet obscure applications in the corners.
Like this interesting use of negative lookarounds to find matching span tags, even when nested, and delete the
matching sets:
Code:
<span[^<>]*>((?:(?!<(?:/?span)).)*)</span>
The bit on the inside finds only text that does not include the arbitrary string "</?span", inside matching span tags.