Rewritten main regex from if/else into looped process