开发者

Combining regex in jQuery

I have this jQuery code which replaces some HTML character codes with their equivalent:

$('.someText').html()
              .replace(/&/g, '&')
              .replace(/&lt;/g, '<')
              .replace(/&gt;/g, '>');

That works and all, but is there a way to combine those replace oper开发者_开发知识库ations all into one regex to make the code more concise?

I'm still wrapping my head around regular expressions


This question has a solution that is more flexible, in case you ever expand beyond just the basic three entities:

Converting sanitised html back to displayable html


I answered a similar question a while ago. Simple answer; there may be a way to do it, but it's probably better to do what you have here. Each replacement is it's own operation, so might as well leave it that way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜