Is it safe to masturbate while pregnant?

Yes. If it is safe to have sex, it is safe to masturbate. If concerned, ask your obstetrician.
Yes. Unless you have a high risk pregnancy and your doctor specifically limits any sexual activity, it is safe to masturbate or have sex.