title: regex and rename the variables in python
body: <p>I am trying to regex the variables from a file; the files look like:</p>
  
  <pre><code>   ...unknown lines...
      @    legend hgap 1
      @     s0  legend  "foo"
      @     s2  legend  "bar"
      ...unknown lines
  </code></pre>
  
  <p>a simple regex is </p>
  
  <pre><code>^@[ \t]*s\d*[ \t]*(legend)[ \t]*[A-z0-9"_]*
  </code></pre>
  
  <p>that matches my need. </p>
  
  <p>But now, I need to rename <code>S0</code> (yes,capital <code>S</code>) to <code>foo</code> and S1 to <code>bar</code>.
  How I can do that?</p>