Regularity for a class of subelliptic operators