var html = xhtml; while(1) { var stylesRe = /(.*?)<\/span>/gi; var styles = stylesRe.exec(xhtml); if(!styles) { break; } var css = styles[1].split(";"); var tags = new Array(); var end = new Array(); for(var i=0;i=0;i--) { txt += '[/'+end[i]+']'; } html = html.replace(styles[0],txt); } xhtml = html;