Yes, recognizing it asap is good, then replacing that with a prayer and then, replace that word or phrase!
While the attitude/reason behind your profanity will continue to be the same until you do get it changed, you need to replace the publicly offensive words with other ones!
How far you go on this is up to you. Because of the way humans learn, this will help you instead of trying to go cold turkey with a long term habit.
A little girl used to repeat the words she heard her dad say, whenever she because frustrated. Her mom taught to say "dishrag!" instead... while they worked on not becoming so frustrated when things don't go her way.
I suspect control issues are behind your attitude and need to vent. Put God back into control, work towards allowing all things to occur irl while you work to accept or change them. Praise GOD in spite of what occurs, count it all joy. This attitude makes the devil really angry and also allows God to bless you.
Maybe use a phrase like, "Praise the Lord anyway! !!!!!!!" It will retrain your brain while also giving a testimony (one that you want anyway, right?)
You can do this.