I'm not certain why that expression would match instances with spans or text inside the anchor tags. It shouldn't really.
You might try:
Code:
<a class="([^>]*?)" id="([^>]*?)"></a>
instead ... just to check.
But I can't get your expression to misbehave, really. It seems to do (for me anyway) what you've intended it to do. Can you give any examples of code it's matched that you don't think it should match?