title: Matlab: How to replace dynamic part of string with regexprep
body: <p>I have strings like</p>
  
  <pre><code>@(foo) 5 + foo.^2
  @(bar) bar(1,:) + bar(4,:)
  </code></pre>
  
  <p>and want the expression in the first group of parentheses (which could be anything) to be replaced by <code>x</code> in the whole string</p>
  
  <pre><code>@(x) 5 + x.^2
  @(x) x(1,:) + x(4,:)
  </code></pre>
  
  <p>I thought this would be possible with <code>regexprep</code> in one step somehow, but after reading the docu and fiddling around for quite a while, I have not found a working solution, yet.</p>
  
  <p>I know, one could use two commands: First, grab the string to be matched with <code>regexp</code> and then use it with <code>regexprep</code> to replace all occurrences.</p>
  
  <p>However, I have the gut feeling this should be somehow possible with the functionality of dynamic expressions and tokens or the like.</p>