If you do take
dragonchild's advice, and look at regular expressions for this task, make sure you look at the
Regexp::Common module. It has very useful features to make building complicated regular expressions easier, like matching balanced delimiters.