In fact, there never was need to use a loop for it. By placing the moderator "g" (global) after the end slash of a regular expression, it'll look for all matches and replace all matches.
Also, don't forget people can use hexadecimal codes like [c=#ff00ff]...[/c]!!!