Start with Understanding
The English terms sympathy and compassion go back to Greek and Latin words, respectively, which originally referred to a "common feeling," something "felt together." For those who wish to provide true comfort to friends or relatives who have lost a baby or a pregnancy, the ancient meanings still ring true. Feelings - what is actually being experienced by the grieving parents and by you in relation to their bereavement - should be at the heart of your expressions of sympathy.
If you wish to interact with the bereaved in a meaningful way, you must start by putting yourself in their shoes and by trying to understand what the child or potential child meant to them and how the death is affecting and will continue to affect their lives.
Understand that the amount of time a child has lived does not determine its importance as a human being or as an object of love. Understand that a new baby can never replace the child who was lost, and that the parents' love for their dead child cannot be "saved" for the future or automatically redistributed among their living children. Understand that the child is the joy of their lives and that the joy didn't end when the child died just as the sorrow doesn't end as soon as the funeral is over. Understand also how important your involvement can be during this painful period of adjustment. There will be few times when you are needed more than you are needed now.