How do I let go of someone who continues to hurt me

Ive been in an on an off relationship with a this man for almost 3 years. Even though I care about him, he continues to hurt me. He and his wife were separated when we met. Now he's going through a really difficult divorce from her and is taking it really hard. I want to end this relationship, but I don't feel like I can. How can I let go?