title: Choose the pattern in regexprep
body: <p>I have a string in Matlab and a want to replace the third appearance of some pattern in it with another pattern. How can I do this?</p>
  
  <p>For example:</p>
  
  <pre><code>str = 'ter-yu-ter-u-ter-hg';
  patternRemove = 'ter';
  patternAdd = 'mov';
  </code></pre>
  
  <p>answer:</p>
  
  <pre><code>str = 'ter-yu-ter-u-mov-hg';
  </code></pre>