Matrix isolation of Mg2 and Mgn molecules in neon, argon, and nitrogen hosts