In comp.lang.javascript message <
oglegroups.com>, Wed, 14 Mar 2007 11:11:22, pbreah <>
posted:
>I need to figure out a pattern that can match each letter of the
>message, but leaves all the html entities alone.
>
>For example, I have a input like this:
>
><div>
>This is the content < Hello >
></div>
>
>Just as an example to make it more clearer, If I wanted to replace the
>all letters of the message with the number "1" I would have this
>resut:
>
><div>
>1111 11 111 1111111 < 11111 >
></div>
>
>Can anyone help?
The following code, probably slowly, encodes all alphanumeric entities
by adding 999 to their numerical value. Slightly tested.
It is then trivial to replace all remaining letters by "1" and to see
how to reverse the 999.
If your text may contain Russian, use another number or be more careful
about reversing.
St = "<div>\nThis is the content < Hello >\n</div>"
function WOK(P, x) { return P.replace(/(\w)/g, // Encode all chars by x
function (z, p1) {
return String.fromCharCode((p1.charCodeAt(0)+x)) } ) }
St = St.replace(/(&\w+

/g, function (z, p1) { return WOK(p1, +999) } )
More is needed if the message can contain such as <b>no</b>, since the
markup would also need to be protected.
The complete tool should be able to irreversibly obfuscate the content
of a Web page, so that it could be submitted for criticism without
revealing its textual content.
Afterthought : put a semicolon at the beginning and an ampersand at the
end, and replace every letter between a semicolon and the next ampersand
with a "1",
It's a good idea to read the newsgroup and its FAQ. See below.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.