fixing regex builder to ignore ending spacing