IN THE PARSHA:
פרשת כי תבוא includes the תּוֹכ ח ה, where משה רבינו warns the Yidden of the consequences they would suffer if they would not obey Hashem.
These words of משה רבינו were not only warnings of what might happen, but prophecies of events that eventually came to be, including the galus in which we find ourselves today.
Of course, the purpose of these consequences are not חס ושלום just to punish Yidden, but rather as a way to bring us to תשובה and correct our sins.
QUESTION:
Since Hashem created everything with a purpose, including the גלות, why does the גמרא say that Hashem regrets creating גלות?
ANSWER:
We say in Davening לִינוּ מֵאַרְ צֵנוּוּמִפְנֵי חֲט אֵינוּ ג . We are only in גלות because of our sins.
When the גמרא says that Hashem regrets creating גלות, it means to say that since גלות only comes as a result of our sins, it has no inherent positive value (and Hashem could have created consequences other than גלות).
Life Lesson:
We must remember that גלות only came about as a result of sins. It is not where Hashem ח"ו wants us to be. It is a temporary situation from which we will very soon be freed, and we must do what we can do bring about its end even sooner.
Further discussion:
When counting the things that Hashem regrets, why does the תלמוד ירושלמי not include גלות?
(For starters, see אות ב in the שיחה)