title: Regular Express issue - javascript
body: <p>I am trying to replace a text in javascript using a regular expression like following [example of what I am trying to do]:</p>
  
  <pre><code>&lt;html&gt;&lt;head&gt;&lt;/head&gt;
  &lt;body&gt;
    &lt;div id="div1"&gt;&lt;a href="#" title="This is Old"&gt;This is Old&lt;/a&gt;&lt;/div&gt;
    &lt;script&gt; 
      var message = "Hi";
      var str = document.getElementById("div1").innerHTML;
      var newstr = str.replace(/Old/g, "&lt;div onclick='say(\""+message+"\");'&gt;New&lt;/div&gt;");
      document.getElementById("div1").innerHTML = newstr;
      function say(message)
      {
        alert(message);
      }
    &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>This is a sample code of what I am trying to do in a large application. Our script is injected in thrid party html pages, so we dont have control over the html.
  If you run this code, you will see that the text appears to be broken and if you just remove the "Old" from the title tag it will work fine. I cannot change the html, so I have to modify the script to handle this.</p>
  
  <p>Is there a way I can put some regular express that can bypass the replacement of the text in case if it occurs in between "&lt;" and ">"?
  or some other way to solve this. </p>
  
  <p>I cannot use DOM to do the replacement, as it crashed the page when there were too much text, I am doing full page text replacement. </p>
  
  <p>Thanks in advance for your help :)</p>
  
  <p>EDIT: Changed the code to make it working :)</p>