No ideas on the problem, looks fine that I can see. Perhaps try putting some debug print statements in the while() loop and make sure everything is getting set where it should. It sounds like the regex is going wonky somewhere but I don't see how with that test data.