import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "%utilization\\\",.+:\\\"(?<utilization>[\\d\\.]+)";
final String string = "Dataframe row : {\"_c0\":{\"0\":null,\"1\":\"00:00:01\",\"2\":\"13:30:01\"},\"_c1\":{\"0\":null,\"1\":\"CPU\",\"2\":\"all\"},\"_c2\":{\"0\":\"Linux\",\"1\":\"%user\",\"2\":\"1.05\"},\"_c3\":{\"0\":\"3.10.0-1160.76.1.el7.x86_64\",\"1\":\"%nice\",\"2\":\"0.34\"},\"_c4\":{\"0\":\"(fraasdwhbdd1.de.db.com)\",\"1\":\"%system\",\"2\":\"0.83\"},\"_c5\":{\"0\":\"16\\/05\\/23\",\"1\":\"%iowait\",\"2\":\"0.05\"},\"_c6\":{\"0\":\"_x86_64_\",\"1\":\"%steal\",\"2\":\"0.00\"},\"_c7\":{\"0\":\"(8\",\"1\":\"%idle\",\"2\":\"97.73\"},\"_c8\":{\"0\":\"CPU)\",\"1\":\"%utilization\",\"2\":\"2.27\"}}.";
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