javascript - Unescape HTML string till HTML content -
i have html string may escaped multiple times. want write function in pass escaped string , returns unescape string. escaped string may escaped n times.
for example, escaped string is: -
%253cp%253ebbbbbbbbb%253c/p%253e%3cinput%20type%3d%27hidden%27%20id%3d%27grid_7_domtype%27%20class%3d%27alldomobjects%27%20datatype%3d%27subpart%27%3e
if unescape string first time get:-
%3cp%3ebbbbbbbbb%3c/p%3e<input type='hidden' id='grid_7_domtype' class='alldomobjects' datatype='subpart'>
which escaped string. unescape string again, , original content:-
<p>bbbbbbbbb</p><input type='hidden' id='grid_7_domtype' class='alldomobjects' datatype='subpart'>
you go on unescaping until string no longer contains escape sequences, i.e. no longer matches /%[0-9a-f]{2}/
.
class="snippet-code-js lang-js prettyprint-override">var s = "%253cp%253ebbbbbbbbb%253c/p%253e%3cinput%20type%3d%27hidden%27%20id%3d%27grid_7_domtype%27%20class%3d%27alldomobjects%27%20datatype%3d%27subpart%27%3e"; while (s.match(/%[0-9a-f]{2}/i)) { s = unescape(s); } alert(s);
probably improve utilize decodeuricomponent
instead of unescape
though.
javascript html regex string
No comments:
Post a Comment