When I hear this question it makes me think of my son that I lost. I guess I wouldn't take back the short time we had with him, so in that instance, yes. I'm glad I had him, even if he didn't stay with us.
When I think about it in context with ex partners it's more complicated. If I could just have gotten my daughter without him then I wouldn't have had to water time LOL
Every case is individual. For some people it may have been better, for others not. If the relationship was a good one, then yes, it is better to have loved and lost. If the relationship was fraught, then no.
It depends. If it a romantic relationship then you have to weigh your options. If it is evident that the person is going to be trouble then you will have to count if its really worth getting involved with someone like that. Another situation will be getting involved with a married man/woman.