The segments (IIRC) break off and contain eggs. These are excreted to be picked up by herbivores.
They can't, I don't think, regenerate. I'm pretty sure it is simply a matter of taking the correct pill. But then I've only treated the kids pinworms. Not on the same scale.