import re
regex = re.compile((r"(?(?=\([^()\w]*[\w.]+[^()\w]*\))\([^()\w]*([\w.]+)[^()\w]*\)|.)(?=[^{]*\})\n"
r"|\n"
r"(?<!\()(\b\w+\b)(?!\()|ok"))
test_str = "Schedule Schedule{id=45345, name=Real Time Positions, filterType=T0, reportId=372, accFilterId=200779, toEmailAddresses=[], ccEmailAddresses=[], bccEmailAddresses=[], ftpDestinations=[FileTransferDestination{protocol=FTP, server=iftp-prod.na.newedge.int, port=21, username=ITEC-MKT-DAR-PULS3-PRD@USA, password=<63a1120>, path=/USA/Root/Customers/EAGLE_SEVEN/NEW_PULSE}], formats=[CSV], sendBlankReports=false, dfaTag=false, sendIntegratedReports=false, pgp=false, pgpSign=false, cron=* 0/10 5-19 * * 1-7, tz=America/Chicago, rescCron=false, days=[], valid=true, fmtOpts=FormattingOptions{dateFormat=null, useCsvQuotes=false, quote=null, csvSep=null, csvHeader=true, csvFooter=false, csvTextDelim=null}, brand=null, compressionMode=CompressionMode{strategy=NEVER, type=ZIP, multipleFiles=false, useSubfolder=false}, businessDateInFilename=false, failureEmails=ashley.tambunan@newedge.com,matt.douglas@newedge.com, testMode=false, testEmails=null, emailSubj=null, emailBody=null, pgpBeforeCompression=true, reportServer=BO, lastNDays=0, useDateInTimeZone=false, marketId=null} finished successfully\""
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