title: Convert plain string to MAC Address format
body: <p>I am trying to convert some string input into the correct format for working with a MAC address.</p>
  
  <p>So I need to convert</p>
  
  <pre><code>00A0C914C829
  </code></pre>
  
  <p>to</p>
  
  <pre><code>00:A0:C9:14:C8:29
  </code></pre>
  
  <p>I have this <code>PowerShell</code> script to achieve this: </p>
  
  <pre><code>$string = "00A0C914C829"
  $out = $string -replace "([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f])", '$1$2:$3$4:$5$6:$7$8:$9$10:$11$12'
  $out
  </code></pre>
  
  <p>Which outputs: </p>
  
  <pre><code>00:A0:C9:14:C8:29
  </code></pre>
  
  <p>But that regex seems ridiculously long.</p>
  
  <p>Is there some way of making this more concise?</p>
  
  <hr>
  
  <ul>
  <li>I think I need to group each section into variables using <code>()</code>, which is why it is so long. I also tried matching with <code>^([0-9A-Fa-f]){12}$</code>, but this gave the output <code>9$2:$3$4:$5$6:$7$8:$9$10:$11$12</code> (12 groups of 1 character each)</li>
  <li>I also tried the similar regex <code>^(([0-9A-Fa-f]){2}){6}$</code> (6 groups of 2 characters each) and then the replacement: <code>$1:$2:$3:$4:$5:$6</code>, but this gave output <code>29:9:$3:$4:$5:$6</code></li>
  </ul>
  
  <p>I think the problem is that I don't understand how groups work properly ... Would really appreciate if someone could point me in the right direction!</p>