in reply to Faster way to regex this
Are you sure that you don't need to treat the backslash like your other characters?
Your current incarnation will leave foo\bar as-is and convert foo\[ to foo\\[. I'm not certain that that is what you want.