Javascript replace using regexp
Posted
by netcrash
on Stack Overflow
See other posts from Stack Overflow
or by netcrash
Published on 2010-05-27T12:24:12Z
Indexed on
2010/05/27
12:41 UTC
Read the original article
Hit count: 193
<input type="text" value="[tabelas][something][oas]" id="allInput">
<script type="text/javascript">
allInput = document.getElementById('allInput');
var nivel = new Array('tabelas', 'produto');
for (var i =0; i < nivel.length ; i++ )
{
alert(" oi => " + allInput.value + " <-- " + nivel[i]) ;
var re = new RegExp("^\[" + nivel[i] + "\]\[.+\].+", "g");
alert(re);
allInput.value = allInput.value.replace(
re, "OLA");
alert(" oi 2 => " + allInput.value + " <-- " + nivel[i]) ;
}
</script>
Basically I whant to replace "something2 in the [tabelas][something][otherfield] by a number of quantity, I have been playing with regexp and had different results from this using .replace(/expression/,xxx ) and new RegExp() .
Best regards and thank you for any help.
© Stack Overflow or respective owner