var str = "Неста-{bgColor='green'}{color='red'}П{b}л{/b}юс{/color}{/bgColor}-ЖД"; var a = "<span style='background-color:"; var b = "</span>"; var out = str.replace(/\{bgColor='([^\}]*)'\}([\s\S]*?)\{\/bgColor\}/gm,a+"$1"+";' >$2"+b) alert(out)