import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(\\s|\\S){0,40}\\\"([0-9]{1,3})\\\"\\;\\}";
final String string = "a:1:{s:2:\"gr\";s:3:\"214\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"188\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"213\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"169\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"219\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"221\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"211\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"184\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"191\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"16\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"127\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"217\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"200\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"182\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"128\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"17\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"163\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"212\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"166\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"94\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"83\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"27\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"28\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"167\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"168\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"202\";}\n"
+ "a:1:{s:2:\"gr\";s:1:\"7\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"129\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"183\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"26\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"185\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"175\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"29\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"209\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"177\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"178\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"24\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"225\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"224\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"57\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"18\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"208\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"193\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"33\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"10\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"11\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"12\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"173\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"13\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"14\";}\n"
+ "a:1:{s:2:\"gr\";s:1:\"9\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"15\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"195\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"130\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"25\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"50\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"131\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"96\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"19\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"107\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"116\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"364\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"194\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"44\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"171\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"172\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"170\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"20\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"95\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"84\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"22\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"23\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"67\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"118\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"97\";}\n"
+ "a:1:{s:2:\"gr\";s:1:\"6\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"365\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"190\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"82\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"42\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"74\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"76\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"73\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"78\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"68\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"207\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"197\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"77\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"46\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"51\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"206\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"165\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"60\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"61\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"62\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"187\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"176\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"196\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"223\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"117\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"98\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"47\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"198\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"45\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"203\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"205\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"201\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"115\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"58\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"204\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"132\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"48\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"49\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"99\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"594\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"585\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"368\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"81\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"53\";}\n"
+ "a:1:{s:2:\"gr\";s:2:\"52\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"180\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"181\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"179\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"164\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"186\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"174\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"199\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"210\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"369\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"370\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"371\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"372\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"373\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"374\";}\n"
+ "a:1:{s:2:\"gr\";s:3:\"375\";}";
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