<p id="demo">bla bli bla bli bla </p>
The ?=n quantifier matches any string that is followed by a specific string n.
On ne prend pas en compte n dans le remplacement
<script>
function myFunction() {
let patt1 = /bla(?= (bli|bla))/g;
let t = document.getElementById("demo").innerHTML;
t = t.replace(patt1,"moi");
document.getElementById("demo").innerHTML = t;
}
myFunction()
</script>
<p id="demo">bla bli bla bli bla </p>
moi bli moi bli bla
The ?:n quantifier matches any string that is followed by a specific string n.
On prend en compte n dans le remplacement
<script>
function myFunction() {
let patt1 = /bla(?: (bli|bla))/g; // et pris dans le remplacement
let t = document.getElementById("demo").innerHTML;
t = t.replace(patt1,"moi");
document.getElementById("demo").innerHTML = t;
}
myFunction()
</script>
<p id="demo">bla bli bla bli bla </p>
moi moi bla