Hi Steven,
Not sure if you want to understand regular expressions in general or just the solution to your particular problem. If it's the former and you'd be willing to read a book on the subject, I'd recommend "Mastering Regular Expressions" by Jeffrey Friedl. I'm about halfway through now, and think the book is excellent. I'm developing an understanding that I feel is much harder to obtain solely from the documentation that is available online.
Thanks,
Paul