wrote on 03 jan 2007 in comp.lang.javascript
:
Hello,
I am trying to parse a HTML page and want to replace the input
element
The following code fails all the time.
var ex = "<input type=\"hidden\" name=\"__VIEWSTATE\"
id=\"__VIEWSTATE\"
value=\"/wEPDwULLTE2NjEyNTI0MThkGAEFEHNlY3Rpb25zR3JpZFZpZXc PZ2QN271==
/>";
var regEx = new RegExp("<\s*input[^>]*>(.*?)\s*/");
if (ex.match( regEx))
{
alert('match');
}
else
{
alert ('no match');
}
For replacing I would use replace() not match():
<div id='container'>
======== other things ========
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwULLTE2NjEyNTI0MThkGAEFEHNlY3Rpb25zR3JpZFZpZXc PZ2QN271" />
======== other things ========
</div>
<script type='text/javascript'>
var s = document.getElementById('container')
s.innerHTML =
s.innerHTML.replace(/<input ([^>]*)>/gi,'<br>Replacing ...<br>(arguments:
$1)<br>')
</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)