I notice that you use dot star (.*) in one of your regular expressions. This is bad. For a first class explanation, check out Death to Dot Star! by our own Ovid.
While I agree that it is good to understand everything
that Ovid said in that node, I don't agree that .* (or
.*?) should be avoided as a matter of religious principle.
But what do I know? I have beenknown to use goto. :-)
I am really bad (they don't float my boat) at regular expressions, so all I know is that .* is very, very greedy. I was only trying to caution the poster about this greediness.