If your girlfriend's ex is sexting her and she's not telling him to fuck off, break up with her immediately lol I learned that the hard way and waited months before I did anything.
Turns out she had never been dumped before so in a weird way I was proud of the fact that I was the first one to tell her "Fuck this, I'm out." even though I still liked her a lot. She ended up apologizing a year later, a little late but still glad she could see how she was acting. I was butthurt for about a week but soon met a much nicer girl the same semester and I've been satisfied with my decision ever since. Main lesson - don't be afraid to let go if you feel you're being mistreated.