I am trying to replace the text within the HTML document, but when i try to replace, i dont want the class name to be changed (because sometimes the class name will have the same value as that of the content), Just the content needs to be changed by reffering to the lookup table.
Input:
<p class="message">Start guessing message...</p>
<p class="label-highscore">
🥇 My score: <span class="highscore">My highscore is 10</span>
</p>
The data that has to be replaced: original - Changed into
message – messageCA
highscore – highscoreCA
Output:
<p class="message">Start guessing messageCA...</p>
<p class="label-highscore">
🥇 My Score: <span class="highscore">My highscoreCA is 10</span>
</p>
This might be silly as a solution, but if you’re going for a “replace string with string” approach, can’t you use an entire phrase as a match? For example, instead of searching for “highscore” - which will result in wrong matches - can’t you search for “My highscore is” and replace it with “My highscoreCA is” ? This will only work if you have fixed occurrences of these sentences, and if you have just 1 or 2 so that you don’t have to hard-code everything.