split out regex and branch printing into lib