import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^\\}$";
final String string = "{\n"
+ " \"_score\": 1.0,\n"
+ " \"_index\": \"newsvit\",\n"
+ " \"_source\": {\n"
+ " \"content\": \" \\u0641\\u0647\\u06cc\\u0645\\u0647 \\u062d\\u0633\\u0646\\u200c\\u0645\\u06cc\\u0631\\u06cc: \",\n"
+ " \"title\": \"\\u06a9\\u0627\\u0631\\u0647\\u0627\\u06cc \\u0642\\u0627\\u0644\\u06cc\\u0628\\u0627\\u0641 \",\n"
+ " \"lead\": \"\\u062c\\u0627\\u0645\\u0639\\u0647 > \\u0634\\u0647\\u0631\\u06cc - \n"
+ " \\u0645\\u06cc\\u0632\\u06af\\u0631\\u062f\\u06cc \\u062f\\u0631\\u0628\\u0627\\u0631\\u0647 .\",\n"
+ " \"agency\": \"13\",\n"
+ " \"date_created\": 1494518193,\n"
+ " \"url\": \"http://www.khabaronline.ir/(X(1)S(bud4wg3ebzbxv51mj45iwjtp))/detail/663749/society/urban\",\n"
+ " \"image\": \"uploads/2017/05/11/1589793661.jpg\",\n"
+ " \"category\": \"15\"\n"
+ " },\n"
+ " \"_type\": \"news\",\n"
+ " \"_id\": \"2981643\"\n"
+ "}\n"
+ "{\n"
+ " \"_score\": 1.0,\n"
+ " \"_index\": \"newsvit\",\n"
+ " \"_source\": {\n"
+ " \"content\": \"\\u0645/\\u0630\",\n"
+ " \"title\": \"\\u0645\\u0639\\u0646\\u0648\\u06cc\\u062a \\u062f\\u0631 \\u0639\\u0635\\u0631 \",\n"
+ " \"lead\": \"\\u0645\\u062f\\u06cc\\u0631 \\u0645\\u0624\\u0633\\u0633\\u0647 \\u0639\\u0644\\u0645\\u06cc \\u0648 \\u067e\\u0698\\u0648\\u0647\\u0634\\u06cc \\u0627\\u0628\\u0646\\u200c\\u0633\\u06cc\\u0646\\u0627 \\u062f\\u0631 .\",\n"
+ " \"agency\": \"1\",\n"
+ " \"date_created\": 1494521817,\n"
+ " \"url\": \"http://www.farsnews.com/13960221001386\",\n"
+ " \"image\": \"uploads/2017/05/11/1713799235.jpg\",\n"
+ " \"category\": \"20\"\n"
+ " },\n"
+ " \"_type\": \"news\",\n"
+ " \"_id\": \"2981951\"\n"
+ "}\n"
+ "....";
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