regex: rewrite the repetition parsing code