Jeremiah 1:5 records God's word to the prophet: "Before I formed thee in the belly I knew thee; and before thou camest forth out of the womb I sanctified thee." The Hebrew word yada — "knew" — is the deepest intimacy word in the Old Testament. It is the same word used for the knowledge between husband and wife. God's knowledge of a person precedes their formation. A child known in the womb who never arrives in the world is not a child God did not know.
Psalm 34:18 says the Lord is "nigh unto them that are of a broken heart" — the Hebrew qarov means physically near. Pregnancy loss creates a specific, isolating grief because many people around you mourn lightly if at all. But the God who formed the child in the womb and who is nigh to the broken-hearted is not confused about the weight of what was lost.
Commentary is from a charismatic Protestant perspective, drawing on KJV text and public-domain sources including Spurgeon, Andrew Murray, and Matthew Henry.