Just because you wasted some time on the wrong guys and haven't found the right one yet, it doesn't make you a failure. You're only 31. You've still got plenty of time to find someone. Many people take longer than that. Some spend their entire lives in an abusive relationship. The important thing is that you're on the right track now. I don't think most people are able to get their life in good order until after the age of 30. If their love life is good, then it's usually being stuck in the wrong career, or the wrong friends, or something else. It takes time to find your path in life. You must have been doing some things right since you have good friends who care about you. As for the romantic relationships, if you've never been in a good one, it can take a while to recognize that what you have is a bad one. But you should be proud of yourself because now you have recognized it. You've taken the right steps to distance yourself from it. You're a brave person to do that. There is a whole world of good men out there waiting to meet someone like you. Just smile, and be glad that you're on the right path. Try to look forward rather than back. The only point to looking back at those relationships should be so that you know what to avoid, and so that when you do find a good man you know how to appreciate him. Otherwise, you should put them behind you and move on with your life. You're taking steps in the right direction, and that's the only thing that matters.
“This planet has - or rather had - a problem, which was this: most of the people living on it were unhappy for pretty much of the time. Many solutions were suggested for this problem, but most of these were largely concerned with the movement of small green pieces of paper, which was odd because on the whole it wasn't the small green pieces of paper that were unhappy.” ― Douglas Adams, The Hitchhiker's Guide to the Galaxy