# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^\[([\d]{1,2}-[\w]{3,9}-[\d]{4}\s+[\d]{2}:[\d]{2}:[\d]{2}\s+[A-Z]{3,4})\]\s((?s).+?)(?=(?:^\[.+\])|\Z)"
test_str = ("[27-May-2021 05:59:39 UTC] Inpsyde\\Idealo\\WooCommerce\\IdealoException: Plugin \"woocommerce\" must be installed and active in C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-content\\plugins\\idealo-for-woocommerce\\src\\Application.php:172\n"
"[27-May-2021 05:59:39 UTC] PHP Fatal error: Uncaught Error: Class 'ActionScheduler_Lock' not found in C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-content\\plugins\\idealo-for-woocommerce\\vendor\\woocommerce\\action-scheduler\\classes\\abstracts\\ActionScheduler.php:29\n"
"Stack trace:\n"
"#0 C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-content\\plugins\\idealo-for-woocommerce\\vendor\\woocommerce\\action-scheduler\\classes\\ActionScheduler_QueueRunner.php(103): ActionScheduler::lock()\n"
"#1 C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\class-wp-hook.php(292): ActionScheduler_QueueRunner->maybe_dispatch_async_request('')\n"
"#2 C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\class-wp-hook.php(316): WP_Hook->apply_filters(NULL, Array)\n"
"#3 C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\plugin.php(484): WP_Hook->do_action(Array)\n"
"#4 C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\load.php(1072): do_action('shutdown')\n"
"#5 [internal function]: shutdown_action_hook()\n"
"#6 {main}\n"
" thrown in C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-content\\plugins\\idealo-for-woocommerce\\vendor\\woocommerce\\action-scheduler\\classes\\abstracts\\ActionScheduler.php on line 29\n"
"[27-May-2021 05:59:39 UTC] PHP Stack trace:\n"
"[27-May-2021 05:59:39 UTC] PHP 1. {main}() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-admin\\admin-ajax.php:0\n"
"[27-May-2021 05:59:39 UTC] PHP 2. do_action() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-admin\\admin-ajax.php:187\n"
"[27-May-2021 05:59:39 UTC] PHP 3. WP_Hook->do_action() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\plugin.php:484\n"
"[27-May-2021 05:59:39 UTC] PHP 4. WP_Hook->apply_filters() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\class-wp-hook.php:316\n"
"[27-May-2021 05:59:39 UTC] PHP 5. wp_ajax_delete_plugin() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\class-wp-hook.php:292\n"
"[27-May-2021 05:59:39 UTC] PHP 6. wp_send_json_success() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-admin\\includes\\ajax-actions.php:4591\n"
"[27-May-2021 05:59:39 UTC] PHP 7. wp_send_json() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\functions.php:4151\n"
"[27-May-2021 05:59:39 UTC] PHP 8. wp_die() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\functions.php:4125\n"
"[27-May-2021 05:59:39 UTC] PHP 9. _ajax_wp_die_handler() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\functions.php:3421\n"
"[27-May-2021 06:56:26 UTC] PHP Warning: mysqli_real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it.\n"
" in C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\wp-db.php on line 1653\n"
"[27-May-2021 06:56:27 UTC] PHP Stack trace:\n"
"[27-May-2021 06:56:27 UTC] PHP 1. {main}() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-cron.php:0\n"
"[27-May-2021 06:56:27 UTC] PHP 2. require_once() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-cron.php:44\n"
"[27-May-2021 06:56:27 UTC] PHP 3. require_once() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-load.php:37\n"
"[27-May-2021 06:56:27 UTC] PHP 4. require_once() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-config.php:80\n"
"[27-May-2021 06:56:27 UTC] PHP 5. require_wp_db() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-settings.php:124\n"
"[27-May-2021 06:56:27 UTC] PHP 6. wpdb->__construct() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\load.php:545\n"
"[27-May-2021 06:56:27 UTC] PHP 7. wpdb->db_connect() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\wp-db.php:632\n"
"[27-May-2021 06:56:27 UTC] PHP 8. mysqli_real_connect() C:\\Users\\xedin\\Local Sites\\idealo\\app\\public\\wp-includes\\wp-db.php:1653\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