fix infinite loop bug in regsub