'If my string inside a cell contains a word, It will append a word / punctuation infront - Google sheet

I'm looking at a solution where if my google sheet cell contains a word , it will automatically append a word / punctuation. I'm looking at a google app script because I have various conditions.

There are some conditions that I want to put in place.

For example , My cell is North 1 - Staff - ABC , the results I want is OP Staff - North 1 - ABC If it contains North, I will automatically append "OP Staff -" and "ABC" as shown in the image.

Second example : Cell value = ABC If it contains ABC , the results I want is OP Staff - KK - ABC - AAAA I want to append "OP Staff - KK -" and "AAAA"

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source