我有一个HTML实体更换&看起来像这样:JavaScript的正则表达式mulltiple条件
function htmlEntities(str) {
return String(str).replace(/&(?!amp;)/g, '&');
}
其工作正常,不是更换&
但将取代&
如何添加多个条件正则表达式的功能,以便它不会与其他html实体混淆,如:
'
"
>
<
我与测试:
var xxx = "1234 &aaa& aaadas 'xxx' \" kkk <aasd> xxxxxxxxxxxxxxxx <";
console.log(htmlEntities(xxx));
它将取代<
成为&lt;
,这是不是我想要什么,我需要它离开<
非触摸就像例如&aaa&
成为&aaa&
希望你明白我的意思,任何想法?
有超过一个正则表达式(向DOM),例如更好的选择http://stackoverflow.com/questions/7394748/whats-the-right-way-to-decode-a-string-that-has-special-html-entities-in-it/http://stackoverflow.com/问题/ 5796718/html-entity-decode –
为什么要重新发明轮子? – NullUserException