If you want to apologize to your ex-boyfriend over text, here's an example of how you could phrase it:

"Hey [Ex's name], I just wanted to reach out and apologize for how things ended between us. Looking back, I realize that I could have handled things better, and I'm sorry if I hurt you in any way. I hope you're doing well and that we can both move on from this in a positive way. Take care."

It's important to keep in mind that an apology over text may not be as effective as an apology in person or over a phone call, so consider other ways to communicate with your ex if possible. Also, be prepared for the possibility that your ex may not respond or may not be ready to forgive and move on.