Question: I have multiple lines of text in log files in this kind of format:

```
topic, this is the message part, with, occasional commas.

```

How can I split the string from the first comma so I would have the topic and the rest of the message in two different variables?

I've tried using this kind of split, but it doesn't work when there's more commas in the message part.

```
[topic, message] = whole_message.split(",", 2);

```

Answer: 
Use a regex that gets "everything but the first comma". So:

```
whole_message.match(/([^,]*),(.*)/)

```

`[1]` will be the topic, `[2]` will be the message.
That sort of decomposing assignment doesn't work in Javascript (at the present time). Try this:

```
var split = whole_message.split(',', 2);
var topic = split[0], message = split[1];

```

*edit* — ok so "split()" is kind-of broken; try this:

```
var topic, message;
whole_message.replace(/^([^,]*)(?:,(.*))?$/, function(_, t, m) {
  topic = t; message = m;
});

```