I prepared a demo usage of regex which replaces the string with following criteria:
[xyz]= green
['xyz']= darkred
AND= red
var htmlstr= document.getElementById('test').innerHTML;
htmlstr = htmlstr.replace(/\[([^',\]]*[^'])\]/g, "["+ "$1"+"]");
htmlstr = htmlstr.replace(/\['([^']*)'\]/g, "['"+ "$1"+"']");
htmlstr = htmlstr.replace(/\sand\s/gi, " AND ");
document.getElementById('test').innerHTML=htmlstr;
No comments:
Post a Comment