format a string like a date : <p>I'm receiving a "<em>date</em>" represented by a string in the form <strong>yyyymmdd</strong> from a database table over which I have no control. (I cannot modify the type/format of the date field)</p>

<p>I would like to insert the character '<strong>/</strong>' at the right place. (<em>20150113 = 2015/01/13</em>)</p>

<p>As I haven't been able to use <code>new Date('20150113')</code> I am using a regex to insert the slash like so:</p>

<pre><code>string = string.toString().replace(/(^[0-9]{4})/g , "$1\/");
string = string.replace(/(^[0-9\/]{7})/g , "$1\/");
</code></pre>

<p>Is it possible to merge both regexes into one or is there an existing function (angular, javascript) that can understand that date format (<em>20150113</em>)?</p>
