Findings in the cognitive neurosciences suggest that the orbitofrontal cortex, along with other loci, is involved in regret.
Regret is fascinating. Therein you have a comparison between the factual and the counterfactual. You have chosen A (the factual), when you could have chosen B (the counterfactual). By regretting, you are going on a time travel, to that fateful moment of decision making, and wish that you could have chosen the other alternative.
Regret invokes a often dramatic change of your world view. The fact that you have chosen A instead of B reflects the value system that you had at that moment. By regretting, you repent and try to modify, if you can, the frame of cognition and the set of biases and prejudices that led to the regrettable choice, ultimately constituting the person that is you. This reconfiguring of personality is often painful, but is worth every agony in the long run.
Humans too often ignore incidents of failure, trying to forget what have happened. While oblivion is sometimes certainly beneficial, there is a silver lining to every cloud of regret, however thick it is.