str = "some content<script type=\"text/javascript\">var str =
'asdfasdfASDFASDF';<\/script>";
str = str.replace(/(<script.*?>.*?)a(.*?<\/script>)/gim, "$1X$2");
alert(str);
In this example, i want all 'a' between the script tags to be replaced
by 'X', but only the first is replaced. How can I modify this to replace
*all* occurances of 'a'?
/MB
str = str.replace(/(<script.*?>)(.*)(?=<\/script>)/gi, function(x,y,z)
{return y+z.replace(/a/gi,'Z')})
[beware of line break. IE tested]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Thanks. This works well, however only as long as the contents of 'str'
is just one line. It does not find any matches when I have several
lines. I tried adding the m-flag to the regular expressions, but that
didn't work. Can this be solved too?
/MB
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')
[beware of line breaks. IE tested]