import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\/\\*(?!(\\<\\!\\[CDATA\\[)|(\\]\\]>))(.*?)\\*\\/";
final String string = "<script type=\"text/javascript\" src=\"//<?php echo SITE_CDN_STATIC_DOMAIN; ?>/src/js/lib.js?<?php echo CACHEBUST; ?>\"></script>\n"
+ "<?php /*<script type=\"text/javascript\" src=\"//<?php echo SITE_CDN_STATIC_DOMAIN; ?>/src/js/prod.js.php?<?php echo CACHEBUST; ?>\"></script> */ ?>\n"
+ "<script type=\"text/javascript\">\n"
+ "/*<![CDATA[*/ \n"
+ "updateBodyClassContext(); \n"
+ "cookieSetContext();\n\n"
+ "/* Run code on page load */\n"
+ "addEvent(window, 'load', function() \n"
+ "{\n"
+ " /**\n"
+ " *\n"
+ " * Example comment inside of \n"
+ " * CDATA\n"
+ " *\n"
+ " */\n"
+ " document.getElementById('emailm').focus();\n"
+ " if (location.href.indexOf('prereg=2') > -1) document.getElementById('prereg_email').focus();\n"
+ " addEvent(document.getElementById('prereg_form'), 'submit', function(e)\n"
+ " {\n"
+ " var e = (e) ? e : window.event, \n"
+ " regex_email = /^([a-z0-9])(([-a-z0-9._])*([a-z0-9_-]))*@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+(\\.([a-z0-9])([-a-z0-9-])?([a-z0-9])+)+$/i;\n"
+ " if (this.prereg_email.value == '' \n"
+ " || !regex_email.test(this.prereg_email.value))\n"
+ " {\n"
+ " this.prereg_email.focus();\n"
+ " stopEvent(e);\n"
+ " }\n"
+ " });\n"
+ "}); \n"
+ "/*]]>*/\n"
+ "</script>\n"
+ "/* another comment for good measure */\n"
+ "/*and another\n"
+ "*/\n"
+ "/*another*/";
final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
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