The only real way is time. You need to go through the grief process because it is a loss that you're recovering from. Give it time, don't look back because you'll dwell on the "what might of been" just let it go & move on
Getting over an ex isn't easy and it's going to hurt. My ex and I were on and off entirely too much. I would swear "I'm done this time for real!" only to go back around him again. What worked for me finally was to get myself involved in other things so I had no time where I was just sitting thinking about him. It takes time.
Wrote poems and wrote him a two page list thanking him for all he did for me, all the places he took me, how much he taught me by good and bad things he did, how much I grew emotionally being with him. then I thanked him for cheating on me with someone much uglier. Then I sold his classic car and replaced him.