regex matching recursive re impl