1. Accept that feeling regret and self-doubt is normal and uncomfortable.
2. While accepting the feeling and not trying to change it, understand that it is a feeling and, therefore, not evidence of fact (no matter how compelling the feeling may be).
3. Recall a time when you felt strongly about something, and with the passage of some time, you came to feel differently about it. It almost seems like a different thing now, with the perspective that time provides. Know that it is quite possible you are in the same situation now -- how you feel about your "wasted" years may not be how you feel in the future. You may, in fact, come to adopt a very different evaluation of how you spent that time. Accept that you will not have access to this future understanding until more time passes.
4. It's natural to wish for a better past, because it always carries with it the wish for a better present. But when spend time wishing for something we don't have, it makes what we do have seem much worse than it is. When you sit around wishing to change the past, you are throwing away the present. Fortunately, ruminating on wishes and regrets is just a habit, like nail-biting. Every time you catch yourself doing it, know that it's normal, but NOT helpful. Then gently bring your focus back to what you'd like to be getting out of the current moment.
5. This stuff is easy to write, but hard to understand - until one day, you do. Therapists specialize in helping their clients get to the place where they have this sort of perspective deep in their bones. If you have the ability to see a therapist, I'd highly recommend it.