title: Replace string with regular expression
body: <p>I have the below situation</p>
  
  <p><strong>Case 1:</strong> </p>
  
  <p><strong>Input :</strong> <code>X(P)~AK,X(MV)~AK</code></p>
  
  <p><strong>Replace with:</strong> <code>AP</code></p>
  
  <p><strong>Output:</strong> <code>X(P)~AP,X(MV)~AP</code></p>
  
  <p><strong>Case 2:</strong></p>
  
  <p><strong>Input:</strong> <code>X(PH)~B$,X(PL)~B$,X(MV)~AP</code></p>
  
  <p><strong>Replace with</strong>: <code>USD$</code></p>
  
  <p><strong>Output:</strong> <code>X(PH)~USD$,X(PL)~USD$,X(MV)~USD$</code></p>
  
  <p>As can be make out that, always the <code>~&lt;string&gt;</code> will be replaced. </p>
  
  <p>Is it possible to achieve the same through regular expression?</p>
  
  <p>Note:~ Nothing will be known at compile time except the structure. A typical structure</p>
  
  <p>goes like  </p>
  
  <pre><code>X(&lt;Variable Name&gt;)~&lt;Variable Name&gt;
  </code></pre>
  
  <p>I am using C#3.0</p>