The replace()
method works good in Anki, but replaceAll()
– doesn’t. Is there any way to fix it?
Here is some code I’m trying to write to modify the content of the field “Sentence”. It should replace every instance of the word from field {{Word}} with underscores.
Example:
Word: weather
Sentence: Yesterday the weather was very good. I hope today the weather will be even better.
Output: Yesterday the ___ was very good. I hope today the ___ will be even better.
<div class="word" style="display:none">{{Word}}</div>
<div class="sentence" style="display:none">{{Sentence}}</div>
<div class="output"></div>
<script>
word = document.querySelector(".word").textContent;
sentence = document.querySelector(".sentence").textContent;
document.querySelector(".output").textContent = sentence.replaceAll(word, "___");
</script>