# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^[A-ZÀ|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ|È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ|Ì|Í|Ị|Ỉ|Ĩ|Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ|Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ|Ỳ|Ý|Ỵ|Ỷ|Ỹ|Đ][a-zà|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ|è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ|ì|í|ị|ỉ|ĩ|ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ|ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ|ỳ|ý|ỵ|ỷ|ỹ]*(?:[ ][A-ZÀ|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ|È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ|Ì|Í|Ị|Ỉ|Ĩ|Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ|Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ|Ỳ|Ý|Ỵ|Ỷ|Ỹ|Đ][a-zà|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ|è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ|ì|í|ị|ỉ|ĩ|ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ|ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ|ỳ|ý|ỵ|ỷ|ỹ]*)*$"
test_str = ("aaa\n"
"Nguyen Van A1 +/**\n\n"
" 2 + * @fileoverview This is the messaging service worker.\n\n"
" 3 + */\n\n"
" 4 +\n\n"
" 5 +importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js');\n\n"
" 6 +importScripts('https://www.gstatic.com/firebasejs/8.10.0/firebase-messaging.js');\n\n"
" 7 +importScripts('https://cdn.jsdelivr.net/npm/idb@7/build/umd.js');\n\n"
" 8 +importScripts('project-config.js');\n\n"
" 9 +importScripts('init-firebase.js');\n\n"
" 10 +\n\n"
" 11 +// Set the IndexedDB db name, store name and version number.\n\n"
" 12 +const dbName = 'push-notifications';\n\n"
" 13 +const storeName = 'pending';\n\n"
" 14 +const dbVersion = 1;\n\n"
" 15 +\n\n"
" 16 +/**\n\n"
" 17 + * onBackgroundMessage receives Firebase messages.\n\n"
" 18 + * It saves them, displays a notification, and pokes the client to see if it is\n\n"
" 19 + * able to receive messages.\n\n"
" 20 + */\n\n"
" 21 +messaging.onBackgroundMessage((msg) => {\n\n"
" 22 + console.log('service worker received firebase message', msg);\n\n"
" 23 + saveMessage(msg);\n\n"
" 24 + const title = msg.data.title;\n\n"
" 25 + const options = {\n\n"
" 26 + body: msg.data.body,\n\n"
" 27 + requireInteraction: true\n\n"
" 28 + };\n\n"
" 29 + self.registration.showNotification(title, options);\n\n"
" 30 + // Check if the web page is present and can receive messages to display.\n\n"
" 31 + channel.postMessage({\n\n"
" 32 + hello: 'check if the client is able to receive messages',\n\n"
" 33 + });\n\n"
" 34 +});\n\n"
" 35 +\n\n"
" 36 +/**\n\n"
" 37 + * When the user clicks on a notification, we switch to our web page if it's\n\n"
" 38 + * open, or open it in a new tab if it isn't.\n\n"
" 39 + */\n\n"
" 40 +self.addEventListener('notificationclick', (event) => {\n\n"
" 41 + event.notification.close();\n\n"
" 42 + event.waitUntil(\n\n"
" 43 + clients.matchAll({ type: 'window' }).then((clientList) => {\n\n"
" 44 + for (let i = 0; i < clientList.length; i++) {\n\n"
" 45 + const client = clientList[i];\n\n"
" 46 + if (client.url == webSiteUrl && 'focus' in client) {\n\n"
" 47 + return client.focus();\n\n"
" 48 + }\n\n"
" 49 + }\n\n"
" 50 + if (clients.openWindow) {\n\n"
" 51 + return clients.openWindow(webSiteUrl);\n\n"
" 52 + }\n\n"
" 53 + })\n\n"
" 54 + );\n\n"
" 55 +});\n\n"
" 56 +\n\n"
" 57 +/**\n\n"
" 58 + * getDB creates or upgrades the IndexedDB used to store messages and returns\n\n"
" 59 + * the database handle.\n\n"
" 60 + */\n\n"
" 61 +async function getDB() {\n\n"
" 62 + const db = await idb.openDB(dbName, dbVersion, {\n\n"
" 63 + upgrade(db, oldVersion) {\n\n"
" 64 + console.log('creating or upgrading db');\n\n"
" 65 + switch (oldVersion) {\n\n"
" 66 + case 0:\n\n"
" 67 + db.createObjectStore(storeName, {\n\n"
" 68 + keyPath: 'messageId'\n\n"
" 69 + });\n\n"
" 70 + break;\n\n"
" 71 + }\n\n"
" 72 + }\n\n"
" 73 + });\n\n"
" 74 + return db;\n\n"
" 75 +}\n\n"
" 76 +\n\n"
" 77 +/**\n\n"
" 78 + * saveMessage writes a Firebase message to the database.\n\n"
" 79 + */\n\n"
" 80 +async function saveMessage(msg) {\n\n"
" 81 + // Background messages don't have message IDs, so set one using the data\n\n"
" 82 + // value.\n\n"
" 83 + msg.messageId = msg.data.id;\n\n"
" 84 + const db = await getDB();\n\n"
" 85 + db.add(storeName, msg);\n\n"
" 86 +}\n\n"
" 87 +\n\n"
" 88 +/**\n\n"
" 89 + * When the service worker is activated, set up the database.\n\n"
" 90 + */\n\n"
" 91 +self.addEventListener('activate', (event) => {\n\n"
" 92 + getDB();\n\n"
" 93 +});\n\n"
" 94 +\n\n"
" 95 +/**\n\n"
" 96 + * onmessage is called when we receive a message from the client.\n\n"
" 97 + * This is expected to be in response to our message, and signals that the\n\n"
" 98 + * client is ready to receive our pending Firebase messages.\n\n"
" 99 + * We just throw all the pending messages - we don't wait for acknowledgement\n\n"
" 100 + * for each one.\n\n"
" 101 + */\n\n"
" 102 +channel.onmessage = async function(cmsg) {\n\n"
" 103 + console.log('service worker received channel message', cmsg);\n\n"
" 104 + // If the response includes the attribute 'ready', we can send our pending\n\n"
" 105 + // messages.\n\n"
" 106 + if ('ready' in cmsg.data) {\n\n"
" 107 + const db = await getDB();\n\n"
" 108 + console.log(db);\n\n"
" 109 + const tx = db.transaction(storeName, 'readwrite');\n\n"
" 110 + const msgs = await tx.store.getAll();\n\n"
" 111 + // Sort the messages by timestamp, so they don't arrive out of order.\n\n"
" 112 + msgs.sort((a, b) => {\n\n"
" 113 + return (a.timestamp > b.timestamp) ? 1 : ((b.timestamp > a.timestamp) ? -1 : 0);\n\n"
" 114 + });\n\n"
" 115 + //const store = tx.objectStore(storeName);\n\n"
" 116 + for (let i = 0; i < msgs.length; i++) {\n\n"
" 117 + console.log('service worker broadcasting message', msgs[i]);\n\n"
" 118 + channel.postMessage({message: msgs[i]});\n\n"
" 119 + console.log('service worker deleting message', msgs[i].messageId);\n\n"
" 120 + await tx.store.delete(msgs[i].messageId);\n\n"
" 121 + }\n\n"
" 122 + await tx.done;\n\n"
" 123 + }\n")
matches = re.finditer(regex, test_str, re.MULTILINE | re.UNICODE | re.IGNORECASE)
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