I'd also recommend the WHILE loop instead of using regex. It's great that you can do that with regex, but I think that it's usually more helpful to show commands a newer scripter (as I'm guessing the OP is) is familiar with rather than giving them something that they won't understand at all. Also, regex is not always a faster solution. Unless it's faster, it may not be the best choice. Smaller code doesn't necessarily mean better code except in contests.
I always prefer readability over code length and speed over both. The one thing about speed, however... if the speed difference isn't significant, then readability is more important to me.