 <p>I would go with a regex. I am not sure how to do this in Java but in python that would be:</p> <pre><code>(\w+):([ ,\w]+)(,|$) </code></pre> <p>Tested on <a href="http://pythex.org/" rel="nofollow">pythex</a> with input <code>abc:xy z uvw, def:g,hi, mno:rst</code>. The result is:</p> <pre><code>Match 1 1. abc 2. xy z uvw 3. , Match 2 1. def 2. g,hi 3. , Match 3 1. mno 2. rst 3. Empty </code></pre> <p>So for each match you get the key in position 1 and the value in 2. The separator is stored in 3</p>