import re
regex = re.compile(r".*at Logger\.[A-Za-z]+.+\n([\s\S]+)\n[^\n]+(\[as realHandler]|<anonymous>)")
test_str = ("Error\n"
" at Logger._s (/var/user/impl/lib/log.js:7:17)\n"
" at Logger.I (/var/user/impl/lib/log.js:26:22)\n"
" at getWxContext (/var/user/impl/route.js:136:7)\n"
" at route (/var/user/impl/route.js:19:13)\n"
" at EventHandler.exports.main [as realHandler] (/var/user/index.js:14:22)\n"
" at EventHandler.handle (/var/runtime/node8/bootstrap.js:401:28)\n"
" at invoke (/var/runtime/node8/bootstrap.js:204:22)\n"
" at Timeout.setTimeout [as _onTimeout] (/var/runtime/node8/bootstrap.js:133:9)\n"
" at ontimeout (timers.js:475:11)\n"
" at tryOnTimeout (timers.js:310:5)")
match = regex.search(test_str)
if match:
print(f"Match was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
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