import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(%([^:]+):([^%]+)%)";
final String string = "<!DOCTYPE html>/\n\n"
+ "<html>\n"
+ "<head>\n"
+ "<meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html; charset=utf-8\\\" />\n"
+ "<title>Testing the checkAndChangeToUrl-Function (Version 5)</title>\n\n"
+ "<link rel=\\\"stylesheet\\\" type=\\\"text/css\\\" href=\\\"[__protocol__]://[__server__]:[__port__]/weblis-ext3/ext/resources/css/ext-all.css\\\" />\n"
+ "<script type=\\\"text/javascript\\\" src=\\\"[__protocol__]://[__server__]:[__port__]/weblis-ext3/ext/adapter/ext/ext-base-debug.js\\\"></script>\n"
+ "<script type=\\\"text/javascript\\\" src=\\\"[__protocol__]://[__server__]:[__port__]/weblis-ext3/ext/ext-all-debug.js\\\"></script>\n"
+ "<script type=\\\"text/javascript\\\" src=\\\"[__protocol__]://[__server__]:[__port__]/weblis-ext3/ext/locale/ext-lang-de.js\\\"></script>\n\n"
+ "<script type=\\\"text/javascript\\\" src=\\\"[__protocol__]://[__server__]:[__port__]/weblis-resources/js/jquery/jquery-3.2.1.js\\\"></script>\n\n"
+ "<script type=\\\"text/javascript\\\">\n\n"
+ "function checkAndChangeToUrl(url, maxRetries, waitTime, waitFunc, startFunc, successFunc, errorFunc) {\n"
+ "console.log(\\\"ENTER checkAndChangeToUrl('\\\"+url+\\\"', \\\"+maxRetries+\\\", \\\"+waitTime+\\\")\\\");\n"
+ "var nRetry = 0;\n"
+ "var checkUrl = function () {\n"
+ "$.ajax({\n"
+ "url: url,\n"
+ "context: document.body,\n"
+ "crossDomain: true,\n"
+ "error: function(jqXHR, textStatus, errorThrown) {\n"
+ "console.error(textStatus + \\\";\n"
+ "\\\" + errorThrown);\n"
+ "nRetry++;\n"
+ "if (nRetry <= maxRetries) {\n"
+ "waitFunc.call(jqXHR, jqXHR);\n"
+ "console.log(\\\"Retry #\\\" + nRetry);\n"
+ "var timeout = (nRetry == 0 ? 0 : waitTime);\n"
+ "console.log(\\\"timeout = \\\" + timeout);\n"
+ "setTimeout(checkUrl, timeout);\n"
+ "if (nRetry === 1) {\n"
+ "console.log(\\\"**** Try and open the target application ****\\\");\n"
+ "// PROBLEM: parent[.parent].handleExternalEvent() existiert nicht...\n"
+ "startFunc.call(jqXHR, jqXHR);\n"
+ "}\n"
+ "} else {\n"
+ "errorFunc.call(jqXHR, jqXHR);\n"
+ "}\n"
+ "return;\n"
+ "},\n"
+ "success : function(data, textStatus, jqXHR) {\n"
+ "console.log(\\\"Success!\\\");\n"
+ "successFunc.call(jqXHR, jqXHR);\n"
+ "}\n"
+ "}).done(function() {\n"
+ "$( this ).addClass( \\\"done\\\" );\n"
+ "console.log(\\\"Done!\\\");\n"
+ "});\n"
+ "};\n"
+ "// Wir setzen das Ganze in Gang...\n"
+ "checkUrl();\n"
+ "}\n\n"
+ "function test_1(checkUrl, targetUrl, launchUrl) {\n"
+ "//var url = \\\"%param:checkUrl%\\\"; \n"
+ "//var url = \\\"http://localhost:8080/RechercheServlet/rest/forcont/fxLIS?DOKID=1&VID=1&OP=RECEIVE\\\"; \n"
+ "//var url = \\\"http://localhost:8085/gn\\\";\n"
+ "console.log(\\\"VOR checkAndChangeToUrl('\\\"+checkUrl+\\\"', 2, 5000) ...\\\");\n"
+ "var ret = checkAndChangeToUrl(checkUrl, 2, 2000, function(jqXHR) {\n"
+ "console.log(\\\"Waiting...\\\");\n"
+ "}, function(jqXHR) {\n"
+ "console.log(\\\"Start application...\\\");\n"
+ "$.ajax({\n"
+ "url: %param:launchUrl%, //\\\"/opusp-rest/client-action/execute/local/GIS_Launch\\\",\n"
+ "context: document.body,\n"
+ "crossDomain: false, //true, -- SYNCHRONER AUFRUF - SCHWERE SÜNDE...\n"
+ "headers: {\n"
+ "'Accept' : 'application/x-java-jnlp-file', /* application/jnlp */\n"
+ "'Content-Description' : 'File Transfer',\n"
+ "'Content-Disposition' : 'attachment; filename=GIS_Launch.jnlp'\n"
+ "},\n"
+ "error: function(jqXHR, textStatus, errorThrown) {\n"
+ "console.error(\\\"Fehler bei Aktion GIS_Launch:\n"
+ "\\\" + textStatus + \\\";\n"
+ "\\\" + errorThrown);\n"
+ "return;\n"
+ "},\n"
+ "success : function(data, textStatus, jqXHR) {\n"
+ "console.log(\\\"GIS_Launch: Success! JNLP = '\\\" + data + \\\"'\\\");\n"
+ "}\n"
+ "}).done(function() {\n"
+ "$( this ).addClass( \\\"done\\\" );\n"
+ "console.log(\\\"GIS_Launch: Done!\\\");\n"
+ "});\n"
+ "}, function(jqXHR) {\n"
+ "console.log(\\\"Success.\\\");\n"
+ "window.location.href = targetUrl;\n"
+ "}, function(jqXHR) {\n"
+ "console.log(\\\"Error: \\\" + jqXHR.statusText + \\\", jqXHR.state() = \\\" + jqXHR.state());\n"
+ "});\n"
+ "console.log(\\\"LEAVE test_1.\\\");\n"
+ "}\n\n"
+ "function performTest_1() {\n"
+ "test_1(\n"
+ "\\\"[__checkUrl__]\\\", // Parameter: checkUrl, z.B. \\\"http://localhost:8080/RechercheServlet\\\" \n"
+ "\\\"%param:targetUrl%\\\", // Parameter: targetUrl, z.B. \\\"http://localhost:8080/RechercheServlet/rest/forcont/fxLIS?DOKID=1&VID=1&OP=RECEIVE\\\"\n"
+ "\\\"[__launchUrl__]\\\" // Parameter: launchUrl, z.B. \\\"/opusp-rest/client-action/execute/local/GIS_Launch\\\"\n"
+ ")\n"
+ "}\n\n"
+ "$.when($.ready).then(function() {\n"
+ "performTest_1();\n"
+ "});\n\n"
+ "</script>\n"
+ "</head>\n"
+ "<body>\n"
+ "<a id=\\\"test_1\\\" onclick=\\\"performTest_1();\\\"><button type=\\\"button\\\">Perform Test #1</button></a>\n"
+ "</body>\n"
+ "</html>\n";
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