»
EnglishFrenchVietnamese

Print - Text Regular Expression Replacer - JavaScriptBank.com

Full version: jsB@nk » Utility » Search-code » Text Regular Expression Replacer
URL: http://www.javascriptbank.com/text-regular-expression-replacer.html

Text Regular Expression Replacer © JavaScriptBank.comThis is one of regular expression examples on jsB@nk that use RegExp object to find and replace text, but this is simple regular expression code with a few lines.

Full version: jsB@nk » Utility » Search-code » Text Regular Expression Replacer
URL: http://www.javascriptbank.com/text-regular-expression-replacer.html



JavaScript
<script type="text/javascript"><!--// Created by: Corneliu Lucian 'Kor' Rusu :: corneliulucian[at]gmail[dot]comvar words={// Add words here to be changed. Format - 'original':'replacement''Bill':'Linus','IE':'Firefox','Windows XP':'Ubuntu Linux'}var regs=[];for(arg in words){regs[regs.length]=new RegExp(arg,'g')}function replaceText(){var tags=document.getElementsByTagName('body')[0].getElementsByTagName('*');var i=0,t;while(t=tags[i++]){if(t.childNodes[0]){var j=0, c;while(c=t.childNodes[j++]){if(c.nodeType==3){var k=0;for(arg in words){c.nodeValue=c.nodeValue.replace(regs[k],words[arg]);k++;}}}}}}//--></script>


HTML
<ul style="text-align: left;">  <li>Bill</li>  <li>IE</li>  <li>Windows XP</li></ul><p><span onclick="replaceText()"><strong><em>Click here to replace</em></strong></span></p>