Optimize XRegExp's for loops

Optimize XRegExp's for loops.