I have had similar pain from a muscle "knot" in my shoulder. the way the muscle runs toward the ribs it can make it feel like lung pain and for some reason, deep breathes make it worse. have someone find the "sweet spot" in your shoulder or back and push on it with even pressure..you wil feel the pain travel from shoulder to bottom of ribs this will also help to break up the "knot" or see a massage therapist. If this doesn't seem to be the case then obviously look deeper into the cause. Hopefully its as simple as this.
I would recommend imaging of the right shoulder and rib area of course after consulting your PCP/Family Physician.
and my shoulder and under the bottom ribs has the same sharp pain and comes and goes at the same time exactly.
for about 6 months now. doesnt happen every time i yawn tho. just like really big ones. A friend say it could be a lung touching my ribs. But it wouldnt explaing the should pain then.
How long has this been going on?
Costochondritis comes to mind, but I can't say for sure.