Why in the first case, html em tags are printed normally whereas in the second test, they disappear.
var text = "text"; eval("var text = text.replace(/(.*)(ex)(.*)/gi,'$1<em>$2</em>$3');"); console.log(text) //text -> t<em>ex</em>t
but
var textx = text.replace("/(.*)(ex)(.*)/gi",'$1<em>$2</em>$3'); console.log(textx) //textx -> text
I've looked at the documentation https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/eval but can't find an explanation.
Thanks