import re
regex = re.compile(r"\/([a-zA-Z0-9-]+)(?=[^\/]*$)", flags=re.MULTILINE)
test_str = ("[\n"
" {\n"
" \"id\": \"https://asdf.com/lti/api/132456/lineitems/5c3f2665-198c-4895-bd52-8c766f528839\",\n"
" \"startDateTime\": \"2020-10-28 15:26:53.731\",\n"
" \"endDateTime\": \"2020-10-29 15:26:53.731\",\n"
" \"label\": \"Performance Test\",\n"
" \"resourceId\": \"This is resource\",\n"
" \"resourceLinkId\": \"This is resource link id\",\n"
" \"scoreMaximum\": 1,\n"
" \"tag\": \"This is tag\"\n"
" },\n"
" {\n"
" \"id\": \"https://asdf.com/lti/544ddaf1-f248-4fa3-983b-938f531fd78f\",\n"
" \"startDateTime\": \"2920-10-28 15:26:53.731\",\n"
" \"endDateTime\": \"2920-10-29 15:26:53.731\",\n"
" \"label\": \"Performance Testing 2\",\n"
" \"resourceId\": \"This is resource\",\n"
" \"resourceLinkId\": \"This is resource link id\",\n"
" \"scoreMaximum\": 1,\n"
" \"tag\": \"This is tag\"\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