regex - string replace without href in javascript -
<html> <head> <title>test</title> </head> <body> <a href="hello.html">hello</a> <script> var str=document.body.innerhtml; document.body.innerhtml=str.replace(/hello/g, "hi");</script> </body> </html>
in code hello.html , hello change hi.html , hi. don't want replace href="". how write regular expression ?
the following regex replace wil want:
<script> var str=document.body.innerhtml; document.body.innerhtml=str.replace(/(>[^<]*)hello/g, "\1hi"); </script>
but think still fragile, , solution regex replaces in .innerhtml
be... remember regexes hacky solution when trying solve problems involve html/xml parsing.
Comments
Post a Comment