Catholic theology distinguishes contrition, sorrow for sin arising from love of God, from attrition, sorrow arising from fear of punishment, and the Council of Trent taught that contrition, joined to confession and the purpose of amendment, belongs to the sacrament of penance. The Act of Contrition is the prayer in which that sorrow is spoken. Its classic English form, O my God, I am heartily sorry for having offended Thee, and I detest all my sins, goes on to name both motives honestly, dread of the loss of heaven and the pains of hell, and above all the offence against God, who is all good and deserving of all my love, before closing in the firm resolve, with the help of God's grace, to sin no more and to avoid the near occasions of sin.
The formula is a catechism distillation of Tridentine doctrine, teaching the theology of repentance to everyone who memorizes it, and that has always been its double office, prayer and instruction at once. Children preparing for first confession learn it as a matter of course, and its phrases, heartily sorry, near occasions of sin, have entered the common speech of Catholic cultures, small fossils of the catechism carried by generations who recited the act kneeling in the dark of the confessional.