Paper presented at CIFMA 2021 – The 3rd International Workshop on Cognition: Interdisciplinary Foundations, Models and Application, Nazarbayev University, Nur-Sultan, Kazakhstan, and the University of York, York, UK. Monday 6 December 2021 https://www.alandix.com/academic/papers/regret-2021/ Regret seems like a very negative emotion, sometimes even debilitating. However, emotions usually have a purpose, in the case of regret to help us learn from past mistakes. In this paper we first present an informal cognitive account of the way regret is built from a wide range of both primitive and more sophisticated mental abilities. The story includes Skinner-level learning, imagination, emotion, and counter-factual reasoning. When it works well this system focuses attention on aspects of past events where a small difference in behaviour would have made a big difference in outcome – precisely the most important lessons to learn. The paper then takes elements of this cognitive account and creates a computational model, which can be applied in simple learning situations. We find that even this simplified model boosts simple machine learning reducing the number of required training samples by a factor of 3-10. This has theoretical implications in terms of understanding emotion and mechanisms that may cast light on related phenomena such as creativity and serendipity. It also has potential practical applications in improving machine leaning and maybe even alleviating dysfunctional regret.