Your function is a bit more complicated than need be. Also, your regular expression is selecting anything that matches any single character within the brackets [] (that is the meaning of brackets in this context). So, " will match as will /. Since it has the g flag, it selects all instances. Your regex could be simply:
The \ character is the escape character telling the regex that the two //'s are not the end of the regex. I've simplified your function and made a small demo:
Code:
<div id="txt"><pre>
//PackerSetting=0//0.0 cm
SpringSetting=10//200 N/mm
Gear1Setting=0//13/41 (12.615)
</pre>
</div>
<script type="text/javascript">
String.prototype.parsetext=function (){
return this.replace(/\/\//g, "");
}
document.getElementById('txt').innerHTML=document.getElementById('txt').innerHTML.parsetext()
</script>
Or, even more simply:
Code:
<script type="text/javascript">
document.getElementById('txt').innerHTML=document.getElementById('txt').innerHTML.replace(/\/\//g, "");
</script>
Bookmarks