Replace {$id} in the string < td > {$id} {$name} < / td > with 10 and {$name} with Tony

replace the string "< tr > < td > {$id} < / td > < td > {$name} < / td > < / tr >" with {$id} with 10, and {$name} with Tony

var str = "< tr > < td > {$id} < / td > < td > {$name} < / td > < / tr >";

console.log(str.replace(/\{\$id\}/,10));

that"s all I can write. Do I have to write it twice? how can I match more than one at a time and replace it?
Please take a look at it. Thank you very much

Mar.21,2021

subject, you can take a look at the answer downstairs, and I also recommend his answer.

< hr >

I guess that's what you mean str.replace (/\ {\ $id\} (. *)\ {\ $name\} /, '10room1Tony')

but I suggest you write

like this.
var map={"id":"10","name":"Tony"};
var input="<tr><td>{$id}</td><td>{$name}</td></tr>";
/**
**
**/
function setData(dataObj,template){
    return template.replace(/{\$([^{}]+)}/ig,function(match,group1){
        return dataObj[group1];
    });
}
setData(map,input);
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3d2d6-2c389.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3d2d6-2c389.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?