import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=\\\"text\\\": \\\")(.*?hello.*?)(?=\", \\\"type\\\": \\\"text\\\")";
final String string = "{\"root\": {\"type\": \"root\", \"format\": \"\", \"indent\": 0, \"version\": 1, \"children\": [{\"type\": \"paragraph\", \"format\": \"\", \"indent\": 0, \"version\": 1, \"children\": [{\"mode\": \"normal\", \"text\": \"text1 hello text\", \"type\": \"text\", \"style\": \"\", \"detail\": 0, \"format\": 0, \"version\": 1}], \"direction\": \"ltr\"}], \"direction\": \"ltr\"}} hellocat world f\n\n"
+ "{\"root\": {\"type\": \"root\", \"format\": \"\", \"indent\": 0, \"version\": 1, \"children\": [{\"type\": \"paragraph\", \"format\": \"\", \"indent\": 0, \"version\": 1, \"children\": [{\"src\": \"https://images.unsplash.com/photo-1458966480358-a0ac42de0a7a?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w1MjU5NTl8MHwxfHNlYXJjaHwzfHx0cmVlfGVufDB8fHx8MTcxMzk5MjE4OHww&ixlib=rb-4.0.3&q=80&w=1080\", \"type\": \"image\", \"width\": 332, \"height\": \"221.329875\", \"version\": 1, \"alt_text\": \"image\", \"max_width\": 500}, {\"mode\": \"normal\", \"text\": \"dsadsa\", \"type\": \"text\", \"style\": \"\", \"detail\": 0, \"format\": 0, \"version\": 1}], \"direction\": \"ltr\"}, {\"type\": \"paragraph\", \"format\": \"\", \"indent\": 0, \"version\": 1, \"children\": [{\"mode\": \"normal\", \"text\": \"fdsfds\", \"type\": \"text\", \"style\": \"\", \"detail\": 0, \"format\": 0, \"version\": 1}], \"direction\": \"ltr\"}], \"direction\": \"ltr\"}}\n\n"
+ "{\"root\": {\"type\": \"root\", \"format\": \"\", \"indent\": 0, \"version\": 1, \"children\": [{\"type\": \"paragraph\", \"format\": \"\", \"indent\": 0, \"version\": 1, \"children\": [{\"mode\": \"normal\", \"text\": \"nccccchello ddddd\", \"type\": \"text\", \"style\": \"\", \"detail\": 0, \"format\": 0, \"version\": 1}], \"direction\": \"ltr\"}], \"direction\": \"ltr\"}}\n\n"
+ "{\"root\": {\"type\": \"root\", \"format\": \"\", \"indent\": 0, \"version\": 1, \"children\": [{\"tag\": null, \"type\": \"paragraph\", \"start\": null, \"format\": \"\", \"indent\": 0, \"version\": 1, \"children\": [{\"rel\": null, \"src\": null, \"url\": null, \"mode\": \"normal\", \"text\": \"bvcbvc\", \"type\": \"text\", \"style\": \"\", \"title\": null, \"value\": null, \"width\": null, \"detail\": 0, \"format\": 0, \"height\": null, \"indent\": null, \"inline\": null, \"target\": null, \"checked\": null, \"version\": 1, \"alt_text\": null, \"children\": null, \"equation\": null, \"field_id\": null, \"direction\": null, \"max_width\": null, \"field_name\": null, \"field_type\": null, \"highlight_type\": null, \"hidden_field_name\": null, \"hidden_field_value\": null}], \"language\": null, \"video_id\": null, \"direction\": \"ltr\", \"list_type\": null}], \"direction\": \"ltr\"}}\n\n\n"
+ "{\"root\": {\"type\": \"root\", \"format\": \"\", \"indent\": 0, \"version\": 1, \"children\": [{\"tag\": null, \"type\": \"paragraph\", \"start\": null, \"format\": \"\", \"indent\": 0, \"version\": 1, \"children\": [{\"rel\": null, \"src\": null, \"url\": null, \"mode\": \"normal\", \"text\": \"gbfbvc\", \"type\": \"text\", \"style\": \"\", \"title\": null, \"value\": null, \"width\": null, \"detail\": 0, \"format\": 0, \"height\": null, \"indent\": null, \"inline\": null, \"target\": null, \"checked\": null, \"version\": 1, \"alt_text\": null, \"children\": null, \"equation\": null, \"field_id\": null, \"direction\": null, \"max_width\": null, \"field_name\": null, \"field_type\": null, \"highlight_type\": null, \"hidden_field_name\": null, \"hidden_field_value\": null}], \"language\": null, \"video_id\": null, \"direction\": \"ltr\", \"list_type\": null}], \"direction\": \"ltr\"}}";
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