title: How to replace the Nth appearance of a needle in a haystack? (Python)
body: <p>I am trying to replace the Nth appearance of a needle in a haystack.  I want to do this simply via re.sub(), but cannot seem to come up with an appropriate regex to solve this.  I am trying to adapt: <a href="http://docstore.mik.ua/orelly/perl/cookbook/ch06_06.htm" rel="nofollow">http://docstore.mik.ua/orelly/perl/cookbook/ch06_06.htm</a> but am failing at spanning multilines, I suppose.</p>
  
  <p>My current method is an iterative approach that finds the position of each occurrence from the beginning after each mutation.  This is pretty inefficient and I would like to get some input.  Thanks!</p>