Convergence of Regret Matching in Potential Games and Constrained Optimization