title: Jquery: Doing some operations on strings
body: <p>I have a string like this:</p>
  
  <pre><code>Heading
  Some interesting text here
  HeadingSome interesting text hereHeading
  Some interesting text here
  Heading
  Some interesting text here
  </code></pre>
  
  <p>What I want to do, is to add another heading under the third heading so it would end up looking like this:</p>
  
  <pre><code>Heading
  Some interesting text here
  HeadingSome interesting text hereHeadingHeading
  Some interesting text here
  Heading
  Some interesting text here
  </code></pre>
  
  <p>I'm looking for a generalized method to select any heading and append stuff to it.</p>
  
  <p>Here's a second and third example:</p>
  
  <p>I have a string. Let's not use any DOM terms because they cause confusion.</p>
  
  <pre><code>My name is Mark. My name is Mark. My name is Mark. My name is Mark.
  </code></pre>
  
  <p>I want to add the string 'and my car is red" to the third repeat of 'My name is Mark.'</p>
  
  <pre><code>My name is Mark. My name is Mark. My name is Mark and my car is red. My name is Mark.
  </code></pre>
  
  <p>Here's another example:</p>
  
  <pre><code>My car is red. My car is red. My car is red. My car is red.
  </code></pre>
  
  <p>On the fourth repeat I want to change the text to 'My car is blue.'</p>
  
  <pre><code>My car is red. My car is red. My car is red. My car is blue.
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>I asked a potentially related question that I wasn't able to find an answer for. But everyone there says it's easy to do with regex:
  <a href="https://stackoverflow.com/questions/1146027/javascript-string-library">Javascript String Library</a></p>
  
  <p>Edit: Added regex to tags.</p>
  
  <p>I am so confused. Apparently people have take some issue with the question. If you think the question is missing some information, please ask, I'll do my best to create a sensible question.</p>
  
  <p>Edit: Added more examples.</p>
  
  <p>Thanks!</p>