title: Regular expression to match Excel Formula
body: <p>In one of my problems to solve, I do have to substitute my range values in an Excel Formula with their equivalent cell references, i.e., for example, if I have an Excel Formula:</p>
  
  <p>= Sum(F10:F14)</p>
  
  <p>I have to replace it with:</p>
  
  <p>= Sum(F10,F11,F12,F13,F14).</p>
  
  <p>I am trying to match the regular expressions which helps me find </p>
  
  <ol>
  <li>if an Excel Formula has been defined with a pattern which includes: 'Sum' and a ':'</li>
  <li>To extract the cells which are included in the range, as in F10:F14</li>
  </ol>
  
  <p>Somehow, I am stuck at Point 1 :-)</p>
  
  <p>For, this I created the following pattern:</p>
  
  <pre><code>Regex formulaMatcher = new Regex(@"=*SUM\([\w]*[\w,]*[\w]+:[\w]+[\w]*[\w,]*\)*");
  foreach (Match m in formulaMatcher.Matches("=SUM(F55,F151:F159)"))
      m.Value.Dump();
  </code></pre>
  
  <p>Now, the above pattern is working perfectly for the formulas:</p>
  
  <pre><code>        // =SUM(F15,F25,F31:F35)
          // =SUM(F10:F12,F26,F31)
          // =SUM(F45,F55,F61:F63,F40)
          // =F14-SUM(F16:F17)
          // =SUM(F35:F37)
          // =SUM(F10:F13)-F11
          // =SUM(F27:F29)/3
          // =F19-F21+SUM(F22:F23)
          // =ROUND(F43-SUM(F23:F42),2)
          // =SUM(F174:F178)+F134+F120+F97
  </code></pre>
  
  <p>But it is failing for: SUM(F81:F89,F105:F113,F128:F135), i.e., for cases involving multiple range operators within the formula</p>
  
  <p>Please assist me in finding out how I could achieve the above result?</p>
  
  <p>Cheers,
  Anil</p>