Javascript split only once and ignore the rest
a = line.split(/:/);
key = a.shift();
val = a.join(':');
Use the greedy operator (?
) to only split the first instance.
line.split(/: (.+)?/, 2);
If you prefer an alternative to regexp consider this:
var split = line.split(':');
var key = split[0];
var val = split.slice(1).join(":");
Reference: split, slice, join.