title: Dynamic regexprep in MATLAB
body: <p>I have the following strings in a long string:</p>
  
  <pre><code>a=b=c=d;
  a=b;
  a=b=c=d=e=f;
  </code></pre>
  
  <p>I want to first search for above mentioned pattern (X=Y=...=Z) and then output like the following for each of the above mentioned strings:</p>
  
  <pre><code>a=d;
  b=d;
  c=d;
  
  a=b;
  
  a=f;
  b=f;
  c=f;
  d=f;
  e=f;
  </code></pre>
  
  <p>In general, I want all the variables to have an equal sign with the last variable on the extreme right of the string. Is there a way I can do it using regexprep in MATLAB. I am able to do it for a fixed length string, but for variable length, I have no idea how to achieve this. Any help is appreciated.</p>
  
  <p>My attempt for the case of two equal signs is as follows:</p>
  
  <pre><code>funstr = regexprep(funstr, '([^;])+\s*=\s*+(\w+)+\s*=\s*([^;])+;', '$1 = $3; \n $2 = $3;\n');
  </code></pre>