fixing infinite regex loop