# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"^SQL> (--L-[0-9]{8})(.*?)(?=SQL> --L-[0-9]{8}|\Z)"
test_str = ("SQL> --L-93752133\n"
"SQL> --SELECT table_name, tablespace_name from dba_tables where upper(table_name) like &tablename_from_developer;\n"
"SQL> \n"
"SQL> --L-52852243\n"
"SQL> \n"
"SQL> SELECT log_mode FROM v$database;\n\n"
" LOG_MODE\n"
" ------------\n"
" NOARCHIVELOG\n\n"
"SQL> \n"
"SQL> archive log list\n"
" Database log mode No Archive Mode\n"
" Automatic archival Disabled\n"
" Archive destination USE_DB_RECOVERY_FILE_DEST\n"
" Oldest online log sequence 3\n"
" Current log sequence 5\n"
"SQL> \n"
"SQL> --L-42127143\n"
"SQL> \n"
"SQL> SELECT t.name \"TSName\", e.encryptionalg \"Algorithm\", d.file_name \"File Name\"\n"
" 2 FROM v$tablespace t\n"
" 3 , v$encrypted_tablespaces e\n"
" 4 , dba_data_files d\n"
" 5 WHERE t.ts# = e.ts#\n"
" 6 AND t.name = d.tablespace_name;\n\n"
" no rows selected")
matches = re.finditer(regex, test_str, re.MULTILINE | re.DOTALL)
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