title: C# / Regex - Replacing set of matches with another set of matches
body: <p>I'm trying to turn this string:</p>
  
  <blockquote>
    <p>INSERT INTO [main].[sqlite_default_schema].[TableName] (<strong>[SomeColumn],
    [SomeOtherColumn], [Last]</strong>) VALUES (<strong>@param1, @param2, @param3</strong>);</p>
  </blockquote>
  
  <p>into this one:</p>
  
  <blockquote>
    <p>INSERT INTO [main].[sqlite_default_schema].[TableName] ([SomeColumn],
    [SomeOtherColumn], [Last]) VALUES (<strong>@SomeColumn, @SomeOtherColumn,
    @Last</strong>);</p>
  </blockquote>
  
  <p>As a beginner in regex, i'm using this C# snippet:</p>
  
  <pre><code>Regex regex = new Regex(@"\(.*?\)");
  MatchCollection matches = regex.Matches(commandText);
  if (matches[0].Success &amp;&amp; matches[1].Success)
  {
      Regex reColNames = new Regex(@"\[\w*\]");
      MatchCollection colNames = reColNames.Matches(matches[0].Value);
      Regex reParamNames = new Regex(@"\@\w*");
      MatchCollection paramNames = reParamNames.Matches(matches[1].Value);
      if (colNames.Count &gt; 0 &amp;&amp; colNames.Count == paramNames.Count)
      {
          for (int i = 0; i &lt; paramNames.Count; i++)
          {
              string colName = colNames[i].Value.Substring(1, colNames[i].Length - 2);
              commandText = commandText.Replace(paramNames[i].Value, "@" + colName);
          }
      }
  }
  return commandText;
  </code></pre>
  
  <p>This works but doesn't feel right. 
  Is there a way to achieve the same result by using just one regex?</p>
  
  <p>Cheers!</p>