fix issue in WriteCode where inversion ignores regex in template

fix issue in WriteCode where inversion ignores regex in template