import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\"(user|from)_id\":(-?\\d+)";
final String string = "{\"response\":{\"count\":21854,\"items\":[{\"id\":228162,\"body\":\"๐\",\"user_id\":136649652,\"from_id\":331639485,\"date\":1484581971,\"read_state\":1,\"out\":1,\"random_id\":0,\"emoji\":1},{\"id\":228161,\"body\":\"๐\",\"user_id\":136649652,\"from_id\":136649652,\"date\":1484581970,\"read_state\":1,\"out\":0,\"emoji\":1},{\"id\":228160,\"body\":\"ัััะพัะบะต*\",\"user_id\":136649652,\"from_id\":136649652,\"date\":1484581969,\"read_state\":1,\"out\":0},{\"id\":228159,\"body\":\"ะั\",\"user_id\":136649652,\"from_id\":331639485,\"date\":1484581969,\"read_state\":1,\"out\":1,\"random_id\":0},{\"id\":228158,\"body\":\"๐\",\"user_id\":136649652,\"from_id\":136649652,\"date\":1484581962,\"read_state\":1,\"out\":0,\"emoji\":1},{\"id\":228157,\"body\":\"ะธะปะธ\",\"user_id\":136649652,\"from_id\":136649652,\"date\":1484581962,\"read_state\":1,\"out\":0},{\"id\":228154,\"body\":\"ัั \",\"user_id\":136649652,\"from_id\":136649652,\"date\":1484581935,\"read_state\":1,\"out\":0}";
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