import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^[^]*?`{3}(?:json)?\\n(.*[^]*?)\\n`{3}[^]*?$";
final String string = "```json\n"
+ "[\n"
+ " {\n"
+ " \"questionType\": \"singleselect\",\n"
+ " \"shortDescription\": \"Who will own the Intellectual Property rights developed during the provision of services?\",\n"
+ " \"fullDescription\": \"According to the agreement, who will own the Intellectual Property rights developed during the provision of services?\",\n"
+ " \"options\": [\n"
+ " \"The Consultant\",\n"
+ " \"The Client\",\n"
+ " \"Both parties\"\n"
+ " ]\n"
+ " },\n"
+ " {\n"
+ " \"questionType\": \"multipleselect\",\n"
+ " \"shortDescription\": \"What are included in Intellectual Property rights according to the agreement?\",\n"
+ " \"fullDescription\": \"What are included in Intellectual Property rights according to the agreement? (Select all that apply)\",\n"
+ " \"options\": [\n"
+ " \"Patents\",\n"
+ " \"Design\",\n"
+ " \"Trademark\",\n"
+ " \"Know-how\",\n"
+ " \"Trade secrets\",\n"
+ " \"Other\"\n"
+ " ]\n"
+ " },\n"
+ " {\n"
+ " \"questionType\": \"textinput\",\n"
+ " \"shortDescription\": \"What rights does the Client have regarding the projects and products resulting from the services?\",\n"
+ " \"fullDescription\": \"What specific rights does the Client have regarding the projects and products resulting from the services?\",\n"
+ " \"options\": []\n"
+ " }\n"
+ "]\n"
+ "```";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
final Matcher matcher = pattern.matcher(string);
if (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