Is the pain on the right side under your right ribs and radiating up and into your back, it could be a Gall Bladder attack, I got this recently and went online and got details if it comes on after eating and what you eat, no milk, no eggs, there is a list of foods that you can and cannot eat, the pain is severe so bad if you did go to the ER as a lot of people do they give you MorphineI read that when it came on make a "tea " an infusion in a cup of Flax seeds and it did help you can eat beets and cucumber aswell to help,I have been doing the Natural route as I dont want Surgey, if you put in Gall Bladder into the Search Engine you will see why.it does sound like it some meds will trigger it also check what you are taking.
Is there anything you can identify as the trigger? Does it happen a certain time after going to the restroom? or eating or drinking something? Or are you moving a certain way? Is there anything that links the episodes together? Do you ever vomit or have to run to the restroom to urinate or have diahrea?
Anything like that might help come up with some ideas. Anyway though, I'd definitely recommend that you go see a general practitioner or family doctor, let him know what's happening and see what tests he'd run to get the ball rolling. Anytime you have any kind of severe pain like that, it's worth a trip to a doctor.