Regular expression matching replacement problem?

string 1
test ()
to replace with->
print ("test ()")

string 2
test (a, b)
to be replaced by->
print ("test (a, b)", a, b)

how to write matching and replacing regularities, can they be implemented with regular substitutions?

^(test\((.*)\))$
->
print\("\1"\, \2\)

if I write the string 1 like this, I can"t replace..

correctly.
Mar.11,2022

/^(test\((.*)*\))$/

var str = "test(p1,p2)";
var reg = /^test\((.*)\)$/;
var changeStr = str.replace(reg,function(match,$1){ return $1?`print("${match}",${$1})`:`print("${match}")`});
console.log(changeStr);

clipboard.png






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-1b35515-2bf7e.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-1b35515-2bf7e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?