# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$"
test_str = ("/*!\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"
" };")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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 Python, please visit: https://docs.python.org/3/library/re.html