JSFiddle - React, Tailwind, and code Playground

by zakariamouhid

HTML

<p id="demo">Click the button to replace "Microsoft" with [www.example.com]اضفط هنا(cut) in the paragraph below:</p>

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
    var str = document.getElementById("demo").innerHTML; 
    var res = str.replace(/\[(.*?)\](.*?)\(cut\)/g, '<a href="https://test.com/?f=$1">$2</a>');
    console.log(res);
   document.getElementById("demo").innerHTML = res;
}
</script>