['test1', 'test2', 'test3']
is a JSON array so it can be parsed with Gson or Jackson. Although JSON usually mandates using double quotes around String
values, Gson will still parse single quotes:
String json = "['test1', 'test2', 'test3']";
Type listType = new TypeToken<List<String>>() {}.getType();
List<String> list = new Gson().fromJson(json, listType);
System.out.println(list); // [test1, test2, test3]
Alternatively you could use a regular expression. Assuming that values can't contain escaped apostrophe \'
symbol:
String text = "['test1', 'test2', 'test3']";
Pattern pattern = Pattern.compile("'([^']+)'");
Matcher matcher = pattern.matcher(text);
List<String> list = new ArrayList<>();
while (matcher.find()) {
list.add(matcher.group(1));
}
System.out.println(list); // [test1, test2, test3]