only compile while() loop regex once