title: replace string in HTML doc after page loads
body: <p>Ive a html doc with some markup like:</p>
  <pre><code>&lt;p&gt;Substance A, a metabolite enhances serotonergic production in neurons [33088927]. Substance B confers neuroprotection [28388366].  &amp;nbsp;&lt;/p&gt;
  </code></pre>
  <p>After the page loads Id like to find every occurrence in the document where there are square brackets and replace the string with something else, eg [33088927] -&gt; 33088927i.</p>
  <p>Using regex101.com Ive put together a function which finds the instances of square brackets:</p>
  <pre><code>function the_Pubs(){
      window.addEventListener(&quot;load&quot;, function(){
          const regex = /\[(.*?)\]/gm;
          let result;
              while((result = regex.exec(document.documentElement.outerHTML)) !== null) {
                  if (result.index === regex.lastIndex) {
                          regex.lastIndex++;
                          }
  
          result.forEach((match, groupIndex) =&gt; {
          console.log(`Found match, group ${groupIndex}: ${match}`);
              
  });
  }
  })}
  </code></pre>
  <p>How can I replace the found instances?</p>