Input is something like this:
String text = "{\"definitions\":[{\"id\":\"com.sample.evaluationa\",\"name\":\"Evaluationa\",\"vers}{\"id\":\"com.sample.evaluationb\",\"name\":\"Evaluationb\",\"vers}";
And some quotes to make it more transparent
String definitions = "{\"definitions\":[";
String id = "{\"id\":\"";
String name = "\",\"name\":\"";
String rest = "\",\"vers}";
My regular expression then looks like this:
Pattern pattern = Pattern.compile((Pattern.quote(definitions)) +"("+ (Pattern.quote(id)) +"(.+)" +(Pattern.quote(name))+"(.+)"+(Pattern.quote(rest))+")*");
I am looking for id's (com.sample.evaluation)
Matcher regexMatcher = pattern.matcher(text);
while (regexMatcher.find()) {
title = regexMatcher.group(2);
System.out.println(title);
System.out.println("The pattern is " + pattern.pattern());
}
My output looks like this:
com.sample.evaluationa","name":"Evaluationa","vers}{"id":"com.sample.evaluationb
The pattern is \Q{"definitions":[\E(\Q{"id":"\E(.+)\Q","name":"\E(.+)\Q","vers}\E)*
But I want:
com.sample.evaluationacom.sample.evluationb
And what is also interesting but not in the good way, after changing targeted group in cycle
title = regexMatcher.group(2);
I get just (and of course the pattern line)
Evaluationb