The problem is that you are trying to use regular expressions to parse HTML. This is incorrect as it won't work in the general case. I haven't got a mathematical proof but I'm fairly certain that regexps aren't powerful enough to parse HTML correctly.
Use an HTML parser and then dissect the resulting DOM for what you want instead.
A trivial example of how regular expressions can't parse HTML correctly, is that the above expressions (if constructed correctly for what you're trying to do) will still take account of HTML comments. However there are other cases where they will fail too.
Mark