import re
regex = re.compile(r"failing[\w\W]*?\d*\)\s[\w\W]*?\:[\s\S]*?(Assert[\w\W]*?)[\n].*(src[^:]+):(\d+):(\d+)")
test_str = (" 1) validates input\n\n\n"
" 0 passing (660ms)\n"
" 1 failing\n\n"
" 1) statement:propose validates input:\n"
" AssertionError: expected { Object (status, err) } to have a deep property 'err' of 'err1', but got 'Error while fetching the changes from the event store: {}'\n"
" at doAsserterAsyncAndAddThen (node_modules/chai-as-promised/lib/chai-as-promised.js:307:16)\n"
" at .<anonymous> (node_modules/chai-as-promised/lib/chai-as-promised.js:255:21)\n"
" at ctx.(anonymous function) [as property] \n"
" at src/aggregate/index.js:144:100\n"
"(node_modules/chai/lib/chai/utils/overwriteMethod.js:49:33)\n"
" at Context.<anonymous> (src/aggregate/test/index.js:44:36)\n\n\n")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} 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