import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\{\"response\":\\{\"result\":\\[)((\\{\"clientId\":\"(\\d{1,})\")?,?(\"clientName\":\"(\\w{1,})\")?,?(\"projectName\":\"(\\w{1,})\")?,?(\"projectId\":\"(\\d{1,})\")?,?(\"jobName\":\"(\\w{1,})\")?,?(\"jobStatus\":\"([\\w-]{1,})\")?,?(\"hours\":\"([:\\d]{1,})\")?,?(\"assignedBy\":\"([\\w.]{1,})\")?,?(\"description\":\"([\\w]{0,})\")?,?(\"isActive\":\"(true|false{0,})\")?,?(\"fromDate\":\"([\\d-]{0,})\")?,?(\"jobId\":\"([\\d]{0,})\")?,?(\"totalhours\":\"([\\w]{0,})\")?,?(\"ratePerHour\":([\\d]{1,}))?,?(\"compsize\":([\\d]{1,}))?,?(\"jobcolor\":([\\d]{1,}))?,?(\"projectManager\":(\\{\"erecno\":\"([\\d]{1,})\"\\}))?,?(\"deleteAllowed\":(true|false)\\}))(],\"message\":\"Data fetched successfully\",\"uri\":\"\\/api\\/timetracker\\/getjobs\",\"status\":0\\}\\})";
final String string = "{\"response\":{\"result\":[{\"clientId\":\"17096000000079988\",\"clientName\":\"Nuriosan\",\"projectName\":\"Minecraft\",\"projectId\":\"17096000000090003\",\"jobName\":\"PICKAR\",\"jobStatus\":\"In-Progress\",\"hours\":\"00:00\",\"assignedBy\":\"hieu.siah\",\"isActive\":\"true\",\"fromDate\":\"2019-10-11\",\"jobId\":\"17096000000090015\",\"totalhours\":\"\",\"ratePerHour\":0,\"compsize\":0,\"jobcolor\":1,\"projectManager\":{\"erecno\":\"17096000000077005\"},\"deleteAllowed\":false}],\"message\":\"Data fetched successfully\",\"uri\":\"/api/timetracker/getjobs\",\"status\":0}}";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html