Combining regex in jQuery
I have this jQuery code which replaces some HTML character codes with their equivalent:
$('.someText').html()
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/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.
精彩评论