I have tested the second approach and it works.
Thank you very much.
However, I should have said earlier, that the file also contains lines like:
i = 5
j = 3.677
k = true
l = false
Which now can not be parsed anymore.
I changed your code to account for this, if anybody is interested in my solution, here it is:
public static String[] splitConfig(String str) {
System.out.println("splitConfig"+str);
Pattern pattern = Pattern.compile("(\\w+) (=) ([^\"]+|\"[^\"]+\")");
Matcher matcher = pattern.matcher(str);
List<String> matches = new ArrayList<>();
while (matcher.find()) {
for (int i = 1; i <= matcher.groupCount(); i++) {
String matchedStr = matcher.group(i);
matches.add(matchedStr);
}
}
String[] result = matches.toArray(new String[matches.size()]);
System.out.println(Arrays.toString(result));
return result;
}
This will parse the following text, line by line:
a = 5
b = 3.3331
c = false
d = "Hello World"
to this String array:
String[] {
"a", "=", "5",
"b", "=", "3.3331",
"c", "=", "false",
"d", "=", "\"Hello World\""
}
Thank you again, very useful answer.