var str = "Онлайн: 10/456", res = "test", res2 = "2000"; var reg = /(Онлайн: )(\d+)(\/)(\d+)/; str = str.replace(reg, `$1${res}$3${res2}`); alert(str);