Why does this happen?

When you breath and it hurts to breath like if it was almost by your rib it feels like. Sometimes this happens to me idk why I’m around 23 weeks pregoss and out of no where I’ll breathe but it’s hurts to sometimes it eventually goes away but does this have to do with pregnancy?