import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\"28\": (true|false)";
final String string = "{\"1\": true, \"2\": true, \"3\": true, \"4\": true, \"5\": true, \"6\": true, \"7\": true, \"8\": true, \"9\": true, \"10\": true, \"11\": true, \"12\": true, \"13\": true, \"14\": true, \"15\": true, \"16\": true, \"17\": true, \"18\": false, \"19\": false, \"20\": false, \"21\": false, \"22\": false, \"23\": false, \"26\": false, \"27\": false, \"28\": false, \"29\": false, \"30\": false, \"31\": false, \"32\": false, \"33\": false, \"34\": true, \"35\": true, \"36\": false, \"37\": true, \"38\": true, \"39\": false, \"40\": false, \"41\": false, \"42\": false, \"81\": false, \"82\": false}";
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