Here are a few verses which clearly convey this crucial concept:
{Do they not know that it is Allah Who accepts the repentance of His servants and receives (approves) their charity, and that Allah is the Relenting, the Compassionate?} (At-Tawbah 9: 104)
{Say: ‘O My servants who wronged against their souls, do not despair of Allah’s mercy! For Allah forgives all sins; for He is indeed Forgiving, Compassionate.} (Az-Zumar 39: 53)
So do not put off repentance; take the necessary steps immediately, for no one can tell when the death will overtake us. The door of repentance is open so long as we are not in the throes of death, for the Prophet (peace and blessings be upon him) said,
“Allah accepts the repentance of His servant so long as death has not reached his collar bone.” (At-Tirmidhi)
But since we have no way of knowing when death will overtake us, we must never be complacent or slack in hastening to taking steps towards repentance.
While speaking of repentance, we must rush to add, that it cannot be valid unless one takes the following steps:
Repentance, as stated above once accomplished, will undoubtedly wipe out one’s sins, and guarantee him a clean record. The Prophet said:
“One who has repented of a sin (sincerely) is like one who has never sinned at all.” (Ibn Majah)
In conclusion, after sinning, one should not feel despair. Rather one should forward sincere repentance to Allah and rest assured that Allah Almighty will forgive his sin, as long as his repentance meets the above-mentioned conditions of sincerity.
Moreover, you must learn how to forget. The more you look back to your old days of sinful habit, the wider the door is open for Satan to draw you back. Scholars used to resemble this case to that of gazelle being chased by hound. Despite that gazelle is naturally faster in speed, but its frequent looking back weakens its morale and makes it an easy prey for hounds.
Excerpted, with slight modifications, from: muslims.ca