Problema!!
Imaginemos que tengo una lista de opciones
<select name="" id="">
<option value="b">/b/ General</option>
<option value="cgm">/cgm/ Cosplay</option>
<option value="me">/me/ Memes</option>
<option value="soc">/soc/ Social</option>
</select>
Y quiero implementar notificaciones en esta
Asi -> <option value="b">/b/ General (20)</option>
Usar .append() como abajo creará un bucle asi
cada que las notificaciones se actualicen
<option value="b">/b/ General (20)(22)(29)</option>
Sugerencia
<!DOCTYPE html>
<html>
<body>
<p>Regexp</p>
<p id="demo">b (123).</p>
<p id="demo1">soc</p>
<p id="demo2">test !</p>
<button onclick="myFunction()">RegExp</button>
<script>
function myFunction() {
// cuando ya tiene numero
var str = document.getElementById("demo").innerHTML;
var res = str.replace(/\(\d+\)/g, "(456)");
document.getElementById("demo").innerHTML = res;
// cuando no tiene numero
var str = document.getElementById("demo1").innerHTML;
var res = str.replace(/$/g, " (789)");
document.getElementById("demo1").innerHTML = res;
//Cuando tiene un signo de !
var str = document.getElementById("demo2").innerHTML;
var res = str.replace(/!/g, "(100)");
document.getElementById("demo2").innerHTML = res;
}
</script>
</body>
</html>