http://qs321.pair.com?node_id=1108345


in reply to Avoid recursive replacement using regex

Sure, just translate this into JavaScript:

my %k = qw(l < g > & &); print "$_ to ".s/(&)amp;|&(l|g)t;/$k{$+}/reg.$/ for qw( &amp; &amp;lt; &amp;gt; &lt; &gt; );
Prints:
&amp; to & &amp;lt; to &lt; &amp;gt; to &gt; &lt; to < &gt; to >
(sorry) :P