title: Convert string to given regex pattern
body: <p>How to convert the <code>string</code> into the <em>given pattern</em>. Consider pattern can be anything.</p>
  
  <p>Example:</p>
  
  <ul>
  <li>Input String is - <code>1234567890</code></li>
  <li>For Pattern <code>XXXX-XXXX-XX</code> Then Output is - <code>1234-5678-90</code> </li>
  <li>For Pattern <code>XXX-XXX-XXX-X</code> Then Output is - <code>123-456-789-0</code></li>
  <li>For Pattern <code>XXX=XXX=XXX=X</code> Then Output is - <code>123=456=789=0</code></li>
  <li>For Pattern <code>XX-XXX-X-XXXX</code> Then Output is - <code>12-345-6-7890</code></li>
  </ul>
  
  <p>Note: Length of input string may vary.</p>
  
  <p>I have tried as</p>
  
  <pre><code>Console.WriteLine(Regex.Replace("1235645847", ".{1,4}", "$&amp;-").TrimEnd('-'));
  </code></pre>
  
  <p>But it is <em>not dynamic</em> it's working for the <em>first pattern only</em>.</p>
  
  <p>Is it possible to achieve this? Any help is appreciated.</p>