Do you mean "what is a good way of doing this?" or "what is the fastest/most memory-efficient way of doing it?". If it's just how to do it then I would say the above example looks easy enough to crack with a regular expression or did you run into problems with that?