Source for demo by Lee.
(d=document).write('<style>#p,#d{top:0;left:0;white-space:pre;color:#756;width:100%;height:100%;padding:9px;border:none;line-height:20px;position:absolute;background:transparent;font:14px "Courier New"}#p{opacity:0.4}</style><div id="d"></div><textarea id="p"></textarea>');p=d[g="getElementById"]("p");j="push";n="length";function c(a,b){l=[];z=[];for(_ in b){i=0;$=b[_];for(m=a.match(b[_]);$.test(a);)l[j]([$.lastIndex-m[i][n],m[i++][n],_])}l.sort(function(f,k){return f[0]-k[0]});h=0;for(_ in l)if(!((e=($=l[_])[0]+$[1])<=h)){z[j]([h,$[0]-h,g],$);h=e}z[j]([h,a[n],g]);return z}function o(a){t=c(a,{"#288":/\/\/.*|\/\*(.|\n)+\*\//g,"#D24":/".*?"|'.*?'/g,"#08c":/\b(else|switch|break|case|catch|new|finally|null|try|for|continue|function|var|if|return|while|do|with|in)(?!\w)/g});s="";for(i in t){y=t[i];s+="<span style='color:"+y[2]+"'>"+a.substr(y[0],y[1])+"</span>"}return s}p.onkeyup=function(){d[g]("d").innerHTML=o(p.value[u="replace"](/</g,"<")[u](/\\.|&#/g,function(a){return"\\&#"+a.charCodeAt(1)+";"}))}