import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\/\\*[\\s\\S]*?\\*\\/|([^:]|^)\\/\\/.*$";
final String string = "/*!\n"
+ " * jQuery JavaScript Library v3.6.0\n"
+ " * https://jquery.com/\n"
+ " *\n"
+ " * Includes Sizzle.js\n"
+ " * https://sizzlejs.com/\n"
+ " *\n"
+ " * Copyright OpenJS Foundation and other contributors\n"
+ " * Released under the MIT license\n"
+ " * https://jquery.org/license\n"
+ " *\n"
+ " * Date: 2021-03-02T17:08Z\n"
+ " */\n"
+ "//hellow orld\n"
+ "( function( global, factory ) {\n"
+ "/*\n"
+ "Hell world\n"
+ "*/\n"
+ " \"use strict\";\n\n"
+ " if ( typeof module === \"object\" && typeof module.exports === \"object\" ) {\n\n"
+ " // For CommonJS and CommonJS-like environments where a proper `window`\n"
+ " // is present, execute the factory and get jQuery.\n"
+ " // For environments that do not have a `window` with a `document`\n"
+ " // (such as Node.js), expose a factory as module.exports.\n"
+ " // This accentuates the need for the creation of a real `window`.\n"
+ " // e.g. var jQuery = require(\"jquery\")(window);\n"
+ " // See ticket #14549 for more info.\n"
+ " module.exports = global.document ?\n"
+ " factory( global, true ) :\n"
+ " function( w ) {\n"
+ " if ( !w.document ) {\n"
+ " throw new Error( \"jQuery requires a window with a document https://jquery.org/license\" );\n"
+ " }\n"
+ " return factory( w );\n"
+ " };\n"
+ " } else {\n"
+ " factory( global );\n"
+ " }\n\n"
+ "// Pass this if window is not defined yet\n"
+ "} )( typeof window !== \"undefined\" ? window : this, function( window, noGlobal ) {\n\n"
+ "// Edge <= 12 - 13+, Firefox <=18 - 45+, IE 10 - 11, Safari 5.1 - 9+, iOS 6 - 9.1\n"
+ "// throw exceptions when non-strict code (e.g., ASP.NET 4.5) accesses strict mode\n"
+ "// arguments.callee.caller (trac-13335). But as of jQuery 3.0 (2016), strict mode should be common\n"
+ "// enough that all such attempts are guarded in a try block.\n"
+ "\"use strict\";\n\n"
+ "var arr = [];\n\n"
+ "var getProto = Object.getPrototypeOf;\n\n"
+ "var slice = arr.slice;\n\n"
+ "var flat = arr.flat ? function( array ) {\n"
+ " return arr.flat.call( array );\n"
+ "} : function( array ) {\n"
+ " return arr.concat.apply( [], array );\n"
+ "};\n\n\n"
+ "var push = arr.push;\n\n"
+ "var indexOf = arr.indexOf;\n\n"
+ "var class2type = {};\n\n"
+ "var toString = class2type.toString;\n\n"
+ "var hasOwn = class2type.hasOwnProperty;\n\n"
+ "var fnToString = hasOwn.toString;\n\n"
+ "var ObjectFunctionString = fnToString.call( Object );\n\n"
+ "var support = {};\n\n"
+ "var isFunction = function isFunction( obj ) {\n\n"
+ " // Support: Chrome <=57, Firefox <=52\n"
+ " // In some browsers, typeof returns \"function\" for HTML <object> elements\n"
+ " // (i.e., `typeof document.createElement( \"object\" ) === \"function\"`).\n"
+ " // We don't want to classify *any* DOM node as a function.\n"
+ " // Support: QtWeb <=3.8.5, WebKit <=534.34, wkhtmltopdf tool <=0.12.5\n"
+ " // Plus for old WebKit, typeof returns \"function\" for HTML collections\n"
+ " // (e.g., `typeof document.getElementsByTagName(\"div\") === \"function\"`). (gh-4756)\n"
+ " return typeof obj === \"function\" && typeof obj.nodeType !== \"number\" &&\n"
+ " typeof obj.item !== \"function\";\n"
+ " };\n\n\n"
+ "var isWindow = function isWindow( obj ) {\n"
+ " return obj != null && obj === obj.window;\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