Someone posted similar js when this xkcd was discussed yesterday (<a href="https://news.ycombinator.com/item?id=6696355" rel="nofollow">https://news.ycombinator.com/item?id=6696355</a>), but also missed that js lets you grab nodesets using xpaths directly:<p><pre><code> var snap = document.evaluate('//text()',
document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null);
for (var i=0;i<snap.snapshotLength; i++) {
t=snap.snapshotItem(i);
t.textContent = replace(t.textContent);
}
</code></pre>
In addition your code uses \s\s* when you just mean \s+; also you are using case-insensitive matches for the 'dictRegex' pattern with case-sensitive matches for the individual patterns, so you replace eg 'election' (lower case e) with 'undefined'.<p>Like the other js implementation you're not matching word boundaries (\b).