@tanguatlay,
I prefer "by" but "in" is also acceptable.
This medicine is not recommended for use
by pregnant women unless absolutely necessary.
This is another way "in" could be used:
This medicine is not recommended for use
in pregnancy unless absolutely necessary.