Factorize substr