Praise be to Allah, and may peace and blessings be upon the Messenger of Allah.
A Muslim believes that everything occurs by the decree of Allah, and that whatever Allah wills happens, while whatever He does not will does not happen. Allah تعالى says: ﴿No calamity befalls on the earth or in yourselves except that it is in a Book before We bring it into existence﴾ [Al-Hadid: 22].
A calamity may occur because of a sin or negligence, and it may also be a trial intended to raise ranks and expiate sins. If it occurs because of disobedience, then the obligation is to repent, seek forgiveness, and reform one's conduct. If it is a trial, then the Muslim should be patient, seek reward from Allah, and be content with Allah's decree.
As for regretting negligence in the past, not every form of regret is an objection to divine decree. Regret that motivates a person to repent, reform, and make use of the remainder of his life is praiseworthy regret. What is blameworthy is regret that produces helplessness, distress, and objection, causing a person to remain a prisoner of the past.
For this reason, the Prophet صلى الله عليه وسلم said: “Be keen on what benefits you, seek help from Allah, and do not be helpless. If something happens to you, do not say: ‘If only I had done such and such, it would have been such and such,’ but say: ‘Allah decreed it, and whatever He willed, He did,’ for ‘if only’ opens the door to the work of Satan.” Narrated by Muslim.
Therefore, whoever missed out on education or seeking knowledge during his youth should not continue to regret it and say: “If only I had worked harder then, my situation would have been better.” Rather, he should benefit from his regret by starting now with whatever he is able to do. And whoever's negligence was caused by disobedience should combine repentance with making use of the remainder of his life in goodness.
A Muslim should also understand that the doors of goodness are many, and the path to virtue is not limited to a single avenue. Whoever has missed out on some knowledge can attain other forms of obedience, such as prayer, fasting, Hajj and Umrah, charity, remembrance of Allah, recitation of the Quran, enjoining what is right and forbidding what is wrong, and other good deeds.
The principle, therefore, is that the believer does not become helpless in performing good deeds because of divine decree, nor does he despair over what has passed. Rather, he takes the necessary means, seeks Allah's help, repents from his shortcomings, and makes use of the remainder of his life in what benefits him. As for saying “if only” after something has happened, when the intention is regret, objection, and causing oneself pain, this is among what the Prophet صلى الله عليه وسلم prohibited.
And Allah تعالى knows best.