Search code examples
jqueryhtmlregexhtml-entitieshtml-encode

Decode HTML entities with Regex


I've a large amount of encoded text, like this:

<div id="readingPaneContentContainer" class="ClearBoth"  cmp="cmp" ulr="ulr"><a id="rpFocusElt" href="javascript:void(0)&#59;" style="height:1px&#59;width:1px&#59

I would like de-encode all, so to have (Example):

<div id="readingPaneContentContainer" class="ClearBoth".....

Is possible to do with Regular Expressions?

Any help would be appreciated.

Luca


Solution

  • See this thread - it has your solution for jQuery that works perfectly:

    How to decode HTML entities using jQuery?

    var encoded = '&#60;div id&#61;&#34;readingPaneContentContainer&#34; class&#61;&#34;ClearBoth&#34;  cmp&#61;&#34;cmp&#34; ulr&#61;&#34;ulr&#34;&#62;&#60;a id&#61;&#34;rpFocusElt&#34; href&#61;&#34;javascript&#58;void&#40;0&#41;&#59;&#34; style&#61;&#34;height&#58;1px&#59;width&#58;1px&#59';
    
    var decoded = $("<div/>").html(encoded).text();
    

    Does not use regex.