/ Published in: JavaScript
Apply string.replace() where string has line breaks, and .replace() only happens for the first line of the string! The fix is to turn newlines into unicode characters, run the regex, then turn the unicode back into newlines.
From comp.lang.javascript (thanks, Evertjan):
Expand |
Embed | Plain Text
str = "some content<script type=\"text/javascript\">var str='asdfas\ndfASDFASDF';<\/script>"; str = str.replace(/\n/g,'\uffff').replace(/(<script.*?>)(.*)(?=<\/script>)/gi, function(x,y,z) {return y+z.replace(/a/gi,'Z')}).replace(/\uffff/g,'\n');
You need to login to post a comment.
