The only things that keep me from getting mired in a chasm of regret are the following three thoughts:
(1.) "An error doesn't become a mistake until you refuse to correct it." In other words, think of errors as unavoidable things which will always come up, and which are not worth regretting. The goal is not to avoid making errors (that's impossible). The goal is to efficiently recover from your errors and decrease the likelihood that they will happen again.
(2.) Externalise the part of your personality which causes you to sabotage yourself. Think of it as an obstacle to your true self, rather than part of who you are. In other words, the model you should have is that you are a runner who tripped over a stone, not that you are a runner who decided to stop running.
(3.) If you sabotaged yourself and therefore prevented yourself from accomplishing X, this may simply be a subconscious sign that you knew that you were not ready for X. Think about how you could improve yourself so that you will be more ready for X if the chance comes up again. Many people are "slow learners", or "late bloomers". This doesn't mean that they will never get where they want to be, it just means that they might have to spend longer on self-improvement before they are ready for certain things.