ekaterina22,
let command = "(al) G (al) () () G", reg = /((?<=\()(.*?)(?=\)))|[^()\s]/g, empty = "o";
function interpret(command, reg, empty)
{
return (command.match(reg)||[]).map(a => a ? a.trim() : empty).join("")
}
alert(interpret(command, reg, empty))