JSFiddle - React, Tailwind, and code Playground

HTML

<html>
    <body>
        <script>
        
        function replaceValue(source, find, replacement)
        {
            var s, i, arr = "\\ ^ $ * + ? { } , . ( ) : = ! | [ ] -".split(" ");
            for (i=0; i<arr.length; i++){
                re = new RegExp("\\"+arr[i],"igm");
                find = find.replace(re, "\\"+arr[i]);
            }
          re = new RegExp(find,"igm");
          s = source.replace(re, replacement);
            return s;
        }

        </script>
<form>

<input type=button id="btn" onclick="alert(replaceValue('some value with$val$','$val$','$0.00'));" value="Replace $val$" />

</form>
</body>
</html>