title: How to remove certain string from last line with javascript?
body: <p>I have string that looks something like this</p>
  
  <pre><code>&lt;a href="http://www.page.com/01"&gt;&lt;img src="http://www.domain.com/test.jpg" alt=""/&gt;&lt;/a&gt;&lt;!--nextpage--&gt;
  &lt;a href="http://www.page.com/02"&gt;&lt;img src="http://www.domain.com/test.jpg" alt=""/&gt;&lt;/a&gt;&lt;!--nextpage--&gt;
  &lt;a href="http://www.page.com/03"&gt;&lt;img src="http://www.domain.com/test.jpg" alt=""/&gt;&lt;/a&gt;&lt;!--nextpage--&gt;
  </code></pre>
  
  <p>What I want to do is remove <code>&lt;a href="http://www.page.com/03"&gt;</code> and <code>&lt;/a&gt;&lt;!--nextpage--&gt;</code> on the last line only! so the final output should look like this:</p>
  
  <pre><code>&lt;a href="http://www.page.com/01"&gt;&lt;img src="http://www.domain.com/test.jpg" alt=""/&gt;&lt;/a&gt;&lt;!--nextpage--&gt;
  &lt;a href="http://www.page.com/02"&gt;&lt;img src="http://www.domain.com/test.jpg" alt=""/&gt;&lt;/a&gt;&lt;!--nextpage--&gt;
  &lt;img src="http://www.domain.com/test.jpg" alt=""/&gt;
  </code></pre>
  
  <p>This is what I did so far</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var str = '&lt;a href="page.com/01"&gt;&lt;img src="domain.com/test.jpg" alt=""/&gt;&lt;/a&gt;&lt;!--nextpage--&gt;\n&lt;a href="page.com/02"&gt;&lt;img src="domain.com/test.jpg" alt=""/&gt;&lt;/a&gt;&lt;!--nextpage--&gt;\n&lt;a href="page.com/03"&gt;&lt;img src="domain.com/test.jpg" alt=""/&gt;&lt;/a&gt;&lt;!--nextpage--&gt;\n';
  str = str.slice(0, -20);
  alert(str)</code></pre>
  </div>
  </div>
  </p>
  
  <p>I managed to remove <code>&lt;/a&gt;&lt;!--nextpage--&gt;</code> on the last line. Now I just don't know how to remove <code>&lt;a href="page.com/03"&gt;</code> on the last line. Please note the string will always have different amount of lines and urls</p>