import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\\"response-code\\\":\\\"(?<responsecode>[^\\\"]*)\\\".*\\\"description\\\":\\\"(?<description>[^\\\"]*)\\\"";
final String string = "{\"sim-slot\":\"0\",\"terminal-vendor\":\"Vendor\",\"default-sms-app\":\"own\",\"screen-orientation\":\"portrait\",\"response-code\":\"200\",\"secondary-device-type\":\"\",\"international\":\"0\",\"subject-region\":\"Lat=0,Lon=0,Alt=0,Acc=0\",\"locale\":\"en_US\",\"timestamp\":\"2017-01-19T13:24:22.986+00:00\",\"user-agent\":\"IM-client/OMA1.0 model/brand-5.1 RCSAndrd/0.0.0 COMLib/0.00.00.rev00000\",\"evt-client-version\":\"0.0.0\",\"active-cs-call\":\"no\",\"sbc-ip\":\"99.99.9.999:9999\",\"transaction-id\":\"9aa99a9a-9aa9-99a9-a999-a9a9a999aa00\",\"init-service-tag\":\"audiocall\",\"description\":\"call-sip-invite-parent\",\"call-id\":\"ZZZZZZZZZZZ\",\"app-state\":\"foreground\",\"module\":\"cs\",\"terminal-sw-version\":\"0.0\",\"imsi\":\"99999999999\",\"remote-peer\":\"+99999999999\",\"cell-id\":\"99999\",\"platform\":\"phone-android\",\"client-version\":\"3.10.32.rev74692\",\"direction\":\"outgoing\",\"network-bearer\":\"CELLULAR_LTE\",\"terminal-model\":\"Model\",\"sim\":\"mcc(000),mnc(000)\",\"result\":\"success\",\"identity\":\"+999999999999\",\"device-id\":\"imei(9999999999),tac(99999)\"}";
final Pattern pattern = Pattern.compile(regex);
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