The Prophet ﷺ actually taught us sunnah ways to stop negative thoughts & overthinking.
He ﷺ said:
Do not ever say: "If only I had done this, or that." Because the word 'if' opens the doors of Shaytan.Instead, he taught us to say:
قدَّرَ اللَّهُ وَمَا شَاءَ فَعَلَ
[Qaddarallāhu wa mā shā'a fa'al ]
"Allah decreed, and what He willed, He did."
— (Sahih Muslim 2664)