i want to change this string..
str = "d.w('download');"
to this string..
document.write('download');
somehow its returns..
d.write('dowritenload');
here i dont want to change letters between '' or "" marks and returns d as document.
i tried to find it on w3schools. there are every code's sample but i dont know how to arrange those code with each other in my script ?
What I have tried:
<script>
str = "d.w('download');"
re = str.replace(/d/g, "document");
re = str.replace(/w/g, "write");
document.getElementById("demo").innerHTML=re;
/*
this code returns..
d.write('dowritenload');
but i want this..
document.write('download');
means i don't want to change letters between '' or "" marks and want d as document.
*/
/*
1) i know the problem is with multiple variable "re" which only returns last variable's answer so how to create that as one ?
2) i found on w3schools this which can help me..
re = str.replace(/(d|w)/g, how to set more than one words in this parameter ?);
3) there are 3 d's are in my string but i dont want change those 2 d's in quoted marks.
*/
</script>