I have a macro that use regex in replace command, try to adapt it for your case.
Usually i do not use regex but this code (part of my macro) contains a regex applied in replace.
{
"Name": "Replace_Exact_Match_Multiple",
"CreationDate": "2020-8-26",
"Commands": [
{
"Command": "store",
"Target": "Roma",
"Value": "Variabile"
},
{
"Command": "executeScript_Sandbox",
"Target": "var mystring = ${Variabile}; var replaced = mystring.replace(/^Roma$/, \"RM\"); return replaced",
"Value": "Variabile"
},
{
"Command": "echo",
"Target": "${Variabile}",
"Value": ""
}
]
}