Counterfactual thinking is the practice of contemplating what didn't happen or what could have happened. These counterfactuals can be compared with what did happen to facilitate evaluation and causative explanations and predictions.
There are various types of counterfactuals.
Upward counterfactuals involve thinking about what could have been better. What would have been a more desirable result?
Downward counterfactuals involve thinking about what could have been worse. What would have been a less desirable result?
Additive counterfactuals explore what additional actions you could have taken. What could you (or the other person) have done that you didn't do?
Subtractive counterfactuals explore what actions you could have avoided. What did you (or the other person) do that perhaps you shouldn't have done?
Would the various counterfactuals (alternative outcomes and actions) be evaluated differently, relative to what actually happened, by different actors in the event? (See Perspective shifting and self-distancing)
The combination of upward/downward and additive/subtractive results in four possible counterfactual scenarios and associated emotions.
Upwards additive (regret) - What additional or different things could you have done to get a better result?
Upwards subtractive (guilt) - What things could you have avoided doing to get a better result?
Downwards additive (relief) - What did you avoid doing which, had you done them, would have led to a worse result?
Downwards subtractive (satisfaction) - What things did you do, which had you omitted doing them, would have led to a worse result?
These four orientations can help you to think about things you need to learn, unlearn or re-learn.
Epstude, K., & Roese, N. J. (2008). The functional theory of counterfactual thinking. Personality and Social Psychology Review, 12(2), 168–192. https://doi.org/10.1177/1088868308316091
You could use operant conditioning or VITAE analysis to explore why you or other people did things they might best have avoided or omitted things they could best have included.