We demonstrate a terahertz (THz) frequency comb that is flexible in terms of its frequency range and the number and spacing of comb lines. We use a combination of near-infrared laser diodes, phase modulation, and opto-electronic frequency conversion. The THz comb lines are characterized to be <10MHz by resolving the pressure-dependent collisional broadening of an ammonia molecule rotational mode.