import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "[\\n\\s]*=>[\\n\\s]*\\[[\\n\\s]*(\\([^\\]]+\\))[\\n\\s]*\\]";
final String string = "{\n"
+ " \"outcome\" => \"success\",\n"
+ " \"result\" => {\n"
+ " \"deep-copy-subject-mode\" => false,\n"
+ " \"vault\" => undefined,\n"
+ " \"security-domain\" => {\n"
+ " \"jboss-web-policy\" => {\n"
+ " \"acl\" => undefined,\n"
+ " \"audit\" => undefined,\n"
+ " \"authentication\" => undefined,\n"
+ " \"cache-type\" => \"default\",\n"
+ " \"identity-trust\" => undefined,\n"
+ " \"jsse\" => undefined,\n"
+ " \"mapping\" => undefined,\n"
+ " \"authorization\" => {\"classic\" => {\"policy-modules\" => [{\n"
+ " \"code\" => \"Delegating\",\n"
+ " \"flag\" => \"required\",\n"
+ " \"module-options\" => undefined\n"
+ " }]}}\n"
+ " },\n"
+ " \"other\" => {\n"
+ " \"acl\" => undefined,\n"
+ " \"audit\" => undefined,\n"
+ " \"authorization\" => undefined,\n"
+ " \"cache-type\" => \"default\",\n"
+ " \"identity-trust\" => undefined,\n"
+ " \"jsse\" => undefined,\n"
+ " \"mapping\" => undefined,\n"
+ " \"authentication\" => {\"classic\" => {\"login-modules\" => [\n"
+ " {\n"
+ " \"code\" => \"Remoting\",\n"
+ " \"flag\" => \"optional\",\n"
+ " \"module-options\" => [(\"password-stacking\" => \"useFirstPass\")]\n"
+ " },\n"
+ " {\n"
+ " \"code\" => \"RealmUsersRoles\",\n"
+ " \"flag\" => \"required\",\n"
+ " \"module-options\" => [\n"
+ " (\"usersProperties\" => \"${jboss.server.config.dir}/application-users.properties\"),\n"
+ " (\"rolesProperties\" => \"${jboss.server.config.dir}/application-roles.properties\"),\n"
+ " (\"realm\" => \"ApplicationRealm\"),\n"
+ " (\"password-stacking\" => \"useFirstPass\")\n"
+ " ]\n"
+ " }\n"
+ " ]}}\n"
+ " },\n"
+ " \"jboss-ejb-policy\" => {\n"
+ " \"acl\" => undefined,\n"
+ " \"audit\" => undefined,\n"
+ " \"authentication\" => undefined,\n"
+ " \"cache-type\" => \"default\",\n"
+ " \"identity-trust\" => undefined,\n"
+ " \"jsse\" => undefined,\n"
+ " \"mapping\" => undefined,\n"
+ " \"authorization\" => {\"classic\" => {\"policy-modules\" => [{\n"
+ " \"code\" => \"Delegating\",\n"
+ " \"flag\" => \"required\",\n"
+ " \"module-options\" => undefined\n"
+ " }]}}\n"
+ " }\n"
+ " }\n"
+ " }\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