move regex out of function