title: Insert a character after every n characters but only for the first x occurrences
body: <p>I have a string of 13 characters say XXXXXXXXXXXXX. I wish to enter a hyphen after every three characters but only for the <em>first three</em> occurrences using JQuery and possibly Regular Expressions.</p>
  
  <p>Which means I need my string to be XXX-XXX-XXX-XXXX.</p>
  
  <p>If I use <code>str.replace(/(.{3})/g, "$1-")</code>, <code>str</code> being my string, as I came across in another post, it yields me <code>XXX-XXX-XXX-XXX-X</code>.</p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>Thanks guys.</p>