Here is the code that is not working:
// money related syntax (yellow)
var SyntaxmoneyReg = /\b(StartingCurrency|Hello)(?=[^\w])/g
function myFunction() {
var input = document.getElementById("myInput")
var data = input.value;
document.getElementById("demo").innerHTML = "You wrote: " + data;
data = data.replace(SyntaxmoneyReg, '<span class="code-money">$1</span>');
input.innerHTML = data;
document.getElementById("myInput").focus();
}
.code-money { color:blue; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<body>
<p>Write something in the text field to trigger a function.</p>
<input type="text" id="myInput" oninput="myFunction()" contenteditable="true">
<p id="demo"></p>
</body>
</html>
After my "data.replace" detects a match, everytime I enter a letter I lose focus of the textbox.