Can I stay friends with my friends ex?

So basically, I was friends with this guy and after that, I became friends with his ex (we were all in the same school, I didn't know they were a thing b4) and then I realized that my girl (friend) was still into him and it ended badly. I still want to be friends with the guy, but it would make my girl (friend) not like me.

Can I stay friends with my friends ex?
Post Opinion