# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"Public(?: ReadOnly)? Property (?<prop>.*?)\(\) As [a-zA-Z]*(?: Implements )?.*? End Property"
test_str = ("Imports System.Windows.Forms\n"
"Imports System.Drawing\n"
"Imports CapReportLib\n"
"Imports ReportControls.Database\n"
"Imports System.Threading\n"
"Imports System.ComponentModel\n\n"
"Public Class Report : Implements IReport\n"
"#Region \"Fields\"\n"
" Friend MyReportRunTime As TimeSpan\n"
" Friend MyLastException As New Exception(\"No Errors\")\n"
" Friend RepParams As New ReportParameters()\n"
" Friend Shared DBA As ReportControls.Database.DataAccess\n"
" Private lastResult As New ReportResult(False, New TimeSpan, String.Empty)\n"
" Private Shared delRunReport As IReport.Execute = Nothing\n\n\n"
" Private repSync As ISynchronizeInvoke\n"
" Private repThread As Thread\n"
" Private repHandler As IReport.ReportHandler\n\n"
" Private repParamsSync As ISynchronizeInvoke\n"
" Private threadIsRunning As Boolean = False\n"
" Private Delegate Sub EnableCsvHandler(ByVal enable As Boolean, ByVal value As String)\n"
" Private enableCsv As EnableCsvHandler\n"
" Private csvData As String = String.Empty\n\n"
" Private startDate As Date = Now\n"
" Private endDate As Date = Now\n"
" Private origin As ReportControls.Types.OriginItem\n"
"#End Region\n\n"
"#Region \"Threading\"\n"
" Private Sub RunReportThread()\n"
" threadIsRunning = True\n"
" Dim rs = ExecuteReport()\n"
" If repThread.ThreadState <> ThreadState.AbortRequested Then\n"
" repSync.Invoke(repHandler, New Object() {rs})\n"
" repParamsSync.Invoke(enableCsv, New Object() {True, csvData})\n"
" End If\n"
" threadIsRunning = False\n"
" End Sub\n\n"
" Public Sub ExecuteReportThread() Implements IReport.ExecuteReportThread\n"
" repParamsSync = RepParams\n"
" enableCsv = AddressOf RepParams.EnableCsvExport\n"
" repThread = New Thread(AddressOf RunReportThread)\n"
" repThread.Start()\n"
" End Sub\n\n"
" Public Sub SetReportHandler(ByVal rh As IReport.ReportHandler) Implements IReport.SetReportHandler\n"
" repHandler = rh\n"
" End Sub\n\n"
" Public Sub StopReport() Implements IReport.StopReport\n"
" If repThread Is Nothing Then Return\n\n"
" If repThread.IsAlive Then\n"
" repThread.Abort()\n"
" End If\n"
" End Sub\n\n"
" Public Sub SetSyncInvoke(ByVal syn As ISynchronizeInvoke) Implements IReport.SetSyncInvoke\n"
" repSync = syn\n"
" End Sub\n\n"
" Public Sub SetReportHandler(ByVal rh As IReport.ReportHandler, ByVal syn As ISynchronizeInvoke) _\n"
" Implements IReport.SetReportHandler\n"
" repSync = syn\n"
" repHandler = rh\n"
" End Sub\n\n"
"#End Region\n\n"
"#Region \"Initialize\"\n"
" Public Sub SetOutPut(ByVal pnlControls As Panel) Implements IReport.SetOutPut\n"
" RepParams.Parent = pnlControls\n"
" RepParams.Dock = DockStyle.Fill\n"
" RepParams.Show()\n"
" End Sub\n\n"
" Public Sub SetReportDataAccess(ByVal connectionString As String) Implements CapReportLib.IReport.SetReportConnectionString\n"
" SetDataAccess(New ReportControls.Database.DataAccess(connectionString))\n"
" End Sub\n\n"
" Public Sub SetDataAccess(ByVal db As DataAccess)\n"
" DBA = db\n\n"
" SetOrigins()\n"
" End Sub\n\n"
" Private Sub SetOrigins()\n"
" RepParams.OriginSelector.SetConnectionString(DBA.ConnectionString)\n"
" End Sub\n\n"
" Public Sub SetReportExecute(ByVal exc As IReport.Execute) Implements IReport.SetReportExecute\n"
" delRunReport = exc\n"
" End Sub\n\n"
" Public Sub Dispose() Implements IReport.Dispose\n"
" DBA.Dispose()\n"
" RepParams.Dispose()\n"
" End Sub\n\n"
"#End Region\n\n"
"#Region \"Run Report\"\n"
" Public Function ExecuteReport() As ReportResult Implements IReport.ExecuteReport\n"
" RepParams.CsvButton1.EnableCsvExport(False, String.Empty)\n"
" Dim success As Boolean = True\n"
" Dim startRun = Now\n"
" Dim repData As String = String.Empty\n"
" Try\n"
" If HasValidParametersSelected Then\n"
" \n"
" Dim rep As New DocsStoredReport(startDate, endDate)\n\n\n"
" repData = rep.Execute(origin, RepParams.ChkRunOriginal.Checked)\n\n"
" csvData = rep.CsvOutput\n"
" If Not threadIsRunning Then\n"
" RepParams.CsvButton1.EnableCsvExport(True, rep.CsvOutput)\n"
" End If\n\n"
" End If\n"
" Catch ex As Exception\n"
" success = False\n"
" MyLastException = ex\n"
" End Try\n"
" Dim endRun = Now\n"
" lastResult = New ReportResult(success, endRun - startRun, repData)\n"
" Return lastResult\n"
" End Function\n\n"
" Friend Shared Sub RunReport()\n"
" If delRunReport Is Nothing Then Return\n"
" delRunReport.Invoke()\n"
" End Sub\n\n"
"#End Region\n\n"
"#Region \"Format Output\"\n"
" Public Sub FormatText(ByRef disp As RichTextBox) Implements IReport.FormatText\n"
" Dim iFont As New Font(\"Courier New\", 12, FontStyle.Regular, GraphicsUnit.Pixel)\n"
" disp.SelectAll()\n"
" disp.SelectionFont = iFont\n"
" 'disp.SelectionAlignment = HorizontalAlignment.Center\n\n"
" If disp.Find(DocsStoredReport.Header) = -1 Then Return\n\n"
" disp.SelectionStart = disp.Find(DocsStoredReport.Header)\n"
" disp.SelectionLength = DocsStoredReport.Header.Length\n"
" iFont = New Font(\"Courier New\", 18, FontStyle.Bold, GraphicsUnit.Pixel)\n"
" disp.SelectionFont = iFont\n"
" 'disp.SelectionAlignment = HorizontalAlignment.Center\n\n"
" disp.SelectionStart = disp.Find(DocsStoredReport.DateRange)\n"
" disp.SelectionLength = DocsStoredReport.DateRange.Length\n"
" iFont = New Font(\"Courier New\", 18, FontStyle.Bold, GraphicsUnit.Pixel)\n"
" disp.SelectionFont = iFont\n"
" 'disp.SelectionAlignment = HorizontalAlignment.Center\n\n\n"
" disp.SelectionStart = disp.Find(DocsStoredReport.SubHeader)\n"
" disp.SelectionLength = DocsStoredReport.SubHeader.Length\n"
" iFont = New Font(\"Courier New\", 12, FontStyle.Bold Xor FontStyle.Underline, GraphicsUnit.Pixel)\n"
" disp.SelectionFont = iFont\n"
" 'disp.SelectionAlignment = HorizontalAlignment.Center\n\n"
" disp.SelectionStart = disp.Find(\"Export Files\")\n"
" disp.SelectionLength = \"Export Files\".Length\n"
" iFont = New Font(\"courier new\", 12, FontStyle.Bold, GraphicsUnit.Pixel)\n"
" disp.SelectionFont = iFont\n\n\n"
" disp.SelectionStart = disp.Find(ExportFile.HeaderRow(False))\n"
" disp.SelectionLength = ExportFile.HeaderRow(False).Length\n"
" iFont = New Font(\"Courier New\", 12, FontStyle.Bold Xor FontStyle.Underline, GraphicsUnit.Pixel)\n"
" disp.SelectionFont = iFont\n"
" End Sub\n\n"
" Public Sub FormatText(ByRef lbl As Label) Implements IReport.FormatText\n"
" End Sub\n\n"
" Public Sub FormatTreeView(ByRef trv As TreeView) Implements IReport.FormatTreeView\n"
" End Sub\n\n"
" Public ReadOnly Property DisplayXmlRootNode() As Boolean Implements IReport.DisplayXmlRootNode\n"
" Get\n"
" Return True\n"
" End Get\n"
" End Property\n\n"
" Public ReadOnly Property AttributeDisplay() As XmlAttributeDisplay Implements IReport.AttributeDisplay\n"
" Get\n"
" Return XmlAttributeDisplay.None\n"
" End Get\n"
" End Property\n\n"
" Public ReadOnly Property AttributeDelimiter() As String Implements IReport.AttributeDelimiter\n"
" Get\n"
" Return \" | \"\n"
" End Get\n"
" End Property\n\n"
"#End Region\n\n"
"#Region \"Information\"\n"
" Public ReadOnly Property ReportName() As String Implements IReport.ReportName\n"
" Get\n"
" Return \"Documents Stored\"\n"
" End Get\n"
" End Property\n\n"
" Public ReadOnly Property ReportDescription() As String Implements IReport.ReportDescription\n"
" Get\n"
" Return \"Totals for the documents stored\"\n"
" End Get\n"
" End Property\n\n"
" Public ReadOnly Property ReportExportType() As ExportType Implements IReport.ReportExportType\n"
" Get\n"
" Return ExportType.Text\n"
" End Get\n"
" End Property\n\n"
" Public ReadOnly Property HasValidParametersSelected() As Boolean Implements IReport.HasValidParametersSelected\n"
" Get\n"
" endDate = RepParams.DateRange.GetEndDate\n"
" startDate = RepParams.DateRange.GetStartDate\n"
" origin = RepParams.OriginSelector.SelectedValue\n"
" Return RepParams.ValidParameters\n"
" End Get\n"
" End Property\n\n"
" Public ReadOnly Property ReportHeader() As String Implements IReport.ReportHeader\n"
" Get\n"
" Return String.Empty\n"
" End Get\n"
" End Property\n\n"
" Public Property LastError() As Exception Implements IReport.LastError\n"
" Get\n"
" Return MyLastException\n"
" End Get\n"
" End Property\n\n"
" Public ReadOnly Property ReportResults() As ReportResult Implements IReport.ReportResults\n"
" Get\n"
" Return lastResult\n"
" End Get\n"
" End Property\n\n"
" Public ReadOnly Property AllowExport() As Boolean Implements IReport.AllowExport\n"
" Get\n"
" Return True\n"
" End Get\n"
" End Property\n\n"
" Public ReadOnly Property Parameters() As String Implements IReport.Parameters\n"
" Get\n"
" Dim params As Object() = New Object() _\n"
" {vbNewLine, RepParams.DateRange.GetStartDate.ToShortDateString, _\n"
" RepParams.DateRange.GetEndDate.ToShortDateString}\n"
" Return String.Format(\"StartDate: {1}{0}EndDate: {2}{0}\", params)\n"
" End Get\n"
" End Property\n\n"
" Public Overloads Function ToString() As String Implements IReport.ToString\n"
" Return ReportName\n"
" End Function\n\n"
"#End Region\n"
"End Class\n")
matches = re.finditer(regex, test_str, re.IGNORECASE | 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