import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\"Kubernetes\\.pod\\\":\\\"(?<kubernets_pod>[^\\\"]+)\"";
final String string = "{\"source\":\"fdgdfdfg\",\"log\":\"2023-08-21 04:07:12.400 INFO 42 --- [dfgdf] c.j.t.f.dgf.dfgd.dgf : >>>>||1407|| [POD CleanUp] File deleted from POD : /dfgd/dfgdfgdfg.dat\",\"host\":\"xx-ret353.svr.gg.fghs.net\",\"tags\":[\"_dateparsefailure\"],\"@version\":\"1\",\"Kubernetes.pod\":\"gkp-xcs-services-black-prd-67986d784-b6c5j\",\"s_sourcetype\":\"tyu\",\"@timestamp\":\"2023-08-21T08:07:28.420Z\",\"Kubernetes.namespace\":\"80578d64606-56-fyt-ty-prod\",\"appId\":\"1235\",\"app_id\":\"2345\",\"log_file\":\"/app/logs/app.log\",\"Kubernetes.node\":\"sd-1564sw32b0f.svr.us.sdf.net\"}";
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