add regex compilation outside the function