Optimize XRegExp's for loops