const regex = new RegExp(oldString, 'g'); const replacedWord = stringToBeChanged.replace(regex, newString);