1

My previous question was marked as a duplicate so I'll explain it better this time.

I have a function that runs through a string to find a word, if found then it should be replaced.

function changeWords (str, newWord, oldWord) {
                str = str.replace(new RegExp('\\b' + oldWord + '\\b'), newWord)

        return str;
    };

The problem with this function is it's not replacing words with accent on the first character.

Let's assume:

str = "Sie isst Äpfel"
oldWord = "Äpfel"
newWord = "apple"

after running the function, str should be "Sie isst apple". How can I make it to account "Äpfel"? This only happens if the first character is accented but not if its in the middle. What's causing this?

However if i have:

str = "Sie isst pÄfel"
oldWord = "pÄfel"
newWord = "apple"

str will take the desired result "Sie isst apple"

N.Car
  • 492
  • 1
  • 4
  • 14

0 Answers0