I\'m trying to perform some super simple parsing o log files, so I\'m using String.split
method like this:
String [] parts = input.split(\",\");
I'm afraid, there's no perfect solution for String.split
. Using a matcher for the three parts would work. In case the number of parts is not constant, I'd recommend a loop with matcher.find
. Something like this maybe
final String s = "type=simple, output=Hello, world, repeat=true";
final Pattern p = Pattern.compile("((?:[^\\\\,]|\\\\.)*)(?:,|$)");
final Matcher m = p.matcher(s);
while (m.find()) System.out.println(m.group(1));
You'll probably want to skip the spaces after the comma as well:
final Pattern p = Pattern.compile("((?:[^\\\\,]|\\\\.)*)(?:,\\s*|$)");
It's not really complicated, just note that you need four backslashes in order to match one.