On the formation and expansion of H II regions