The fact that you should even ask this question, and that the proposed solutions, let's say, will be considered less readable :-) should be good evidence that REs are not a real answer to this question.
You would be much better, in terms of readability, to actually code this as a relatively simple parser.
Too often, people try to use RE to be βsmartβ (I don't mean it disparagingly), thinking that one line is elegant, but all they get is an unattainable swamp of characters. I would prefer to fully comment on the 20-line solution, which I can understand in an instant.
source share