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

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -