Question: I want to split a number of strings similar to `name: john, id: 20, dest: toledo, from: seattle, date_time: [2/8/12 15:48:01:837 MST]` into only these tokens:

```
john
20
toledo
seattle
[2/8/12 15:48:01:837 MST]

```

I'm doing this

```
String delims = "(name|id|dest|from|date_time)?[:,\\s]+";
String line = "name: john, id: 20, dest: toledo, from: seattle, date_time: [2/8/12 15:48:01:837 MST]";
String[] lineTokens = line.split(delims, 5);

for (String t : lineTokens)
{
    // for debugging
    System.out.println (t);
    // other processing I want to do
}   

```

but every even element in lineTokens turns out to be either empty or just whitespace. Each odd element in lineTokens is what I want, i.e. lineTokens[0] is "", lineTokens[1] is "john", lineTokens[2] is "", lineTokens[3] is "20", etc. Can anyone explain what I'm doing wrong?

Answer: 
The problem is that your regex is not matching `, id:` as a whole, it is matching `,` as one and then `id:` as a 2nd match. Between these two matches you have an empty string. You need to modify it to match the whole thing. Something like this:

```
String delims = "(, )?(name|id|dest|from|date_time)?[:\\s]+";

```

<http://ideone.com/Qgs8y>
I made some changes to your code:

```
    String delims = "(name|id|dest|from|date_time)[:,\\s]+";
    String line = "name: john, id: 20, dest: toledo, from: seattle, date_time: [2/8/12 15:48:01:837 MST]";
    String[] lineTokens = line.split(delims);

    for (String t : lineTokens)
    {
        // for debugging
        System.out.println (t);
        // other processing I want to do
    }   

```

also you should ignore the first element in lineTokens, since it's the capturing from the beginning of the line till "name:...."