Hi
In VB6 I had a really useful Regular Expression add-in I got somewhere from the web
I thought I'd do my own for .net. Here is the form code. I've not made it into an add in yet, but I thought someone might be interested in it anyway...
Option Strict On
Imports System.Text.RegularExpressions
Public Class frmMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lblNumber As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents lstMatches As System.Windows.Forms.ListBox
Friend WithEvents txtPattern As System.Windows.Forms.TextBox
Friend WithEvents txtSource As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.lblNumber = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label1 = New System.Windows.Forms.Label()
Me.lstMatches = New System.Windows.Forms.ListBox()
Me.txtPattern = New System.Windows.Forms.TextBox()
Me.txtSource = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'lblNumber
'
Me.lblNumber.Location = New System.Drawing.Point(392, 128)
Me.lblNumber.Name = "lblNumber"
Me.lblNumber.Size = New System.Drawing.Size(72, 40)
Me.lblNumber.TabIndex = 20
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 48)
Me.Label2.Name = "Label2"
Me.Label2.TabIndex = 19
Me.Label2.Text = "Pattern"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 18
Me.Label1.Text = "Source"
'
'lstMatches
'
Me.lstMatches.Location = New System.Drawing.Point(8, 128)
Me.lstMatches.Name = "lstMatches"
Me.lstMatches.Size = New System.Drawing.Size(368, 251)
Me.lstMatches.TabIndex = 16
'
'txtPattern
'
Me.txtPattern.Location = New System.Drawing.Point(120, 48)
Me.txtPattern.Name = "txtPattern"
Me.txtPattern.Size = New System.Drawing.Size(176, 20)
Me.txtPattern.TabIndex = 15
Me.txtPattern.Text = ""
'
'txtSource
'
Me.txtSource.Location = New System.Drawing.Point(120, 8)
Me.txtSource.Name = "txtSource"
Me.txtSource.Size = New System.Drawing.Size(360, 20)
Me.txtSource.TabIndex = 14
Me.txtSource.Text = ""
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(504, 405)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblNumber, Me.Label2, Me.Label1, Me.lstMatches, Me.txtPattern, Me.txtSource})
Me.Name = "frmMain"
Me.Text = "frmMain"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub MyExecute()
'takes the source text, outputs all the matches to the match list box
lstMatches.Items.Clear()
'if there is an error, add this to the list box rather than the matches
Try
Dim re As New Regex(txtPattern.Text)
Dim mchs As MatchCollection = re.Matches(txtSource.Text)
Dim mch As Match
For Each mch In mchs
lstMatches.Items.Add(mch.ToString & " (" & mch.Index.ToString & ""
Next
lblNumber.Text = mchs.Count.ToString & " matches found"
Catch ex As Exception
lstMatches.Items.Add(ex.Message)
End Try
End Sub
Private Sub txtSource_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSource.TextChanged
Call MyExecute()
End Sub
Private Sub txtPattern_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPattern.TextChanged
Call MyExecute()
End Sub
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
In VB6 I had a really useful Regular Expression add-in I got somewhere from the web
I thought I'd do my own for .net. Here is the form code. I've not made it into an add in yet, but I thought someone might be interested in it anyway...
Option Strict On
Imports System.Text.RegularExpressions
Public Class frmMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents lblNumber As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents lstMatches As System.Windows.Forms.ListBox
Friend WithEvents txtPattern As System.Windows.Forms.TextBox
Friend WithEvents txtSource As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.lblNumber = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label1 = New System.Windows.Forms.Label()
Me.lstMatches = New System.Windows.Forms.ListBox()
Me.txtPattern = New System.Windows.Forms.TextBox()
Me.txtSource = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'lblNumber
'
Me.lblNumber.Location = New System.Drawing.Point(392, 128)
Me.lblNumber.Name = "lblNumber"
Me.lblNumber.Size = New System.Drawing.Size(72, 40)
Me.lblNumber.TabIndex = 20
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 48)
Me.Label2.Name = "Label2"
Me.Label2.TabIndex = 19
Me.Label2.Text = "Pattern"
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 18
Me.Label1.Text = "Source"
'
'lstMatches
'
Me.lstMatches.Location = New System.Drawing.Point(8, 128)
Me.lstMatches.Name = "lstMatches"
Me.lstMatches.Size = New System.Drawing.Size(368, 251)
Me.lstMatches.TabIndex = 16
'
'txtPattern
'
Me.txtPattern.Location = New System.Drawing.Point(120, 48)
Me.txtPattern.Name = "txtPattern"
Me.txtPattern.Size = New System.Drawing.Size(176, 20)
Me.txtPattern.TabIndex = 15
Me.txtPattern.Text = ""
'
'txtSource
'
Me.txtSource.Location = New System.Drawing.Point(120, 8)
Me.txtSource.Name = "txtSource"
Me.txtSource.Size = New System.Drawing.Size(360, 20)
Me.txtSource.TabIndex = 14
Me.txtSource.Text = ""
'
'frmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(504, 405)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblNumber, Me.Label2, Me.Label1, Me.lstMatches, Me.txtPattern, Me.txtSource})
Me.Name = "frmMain"
Me.Text = "frmMain"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub MyExecute()
'takes the source text, outputs all the matches to the match list box
lstMatches.Items.Clear()
'if there is an error, add this to the list box rather than the matches
Try
Dim re As New Regex(txtPattern.Text)
Dim mchs As MatchCollection = re.Matches(txtSource.Text)
Dim mch As Match
For Each mch In mchs
lstMatches.Items.Add(mch.ToString & " (" & mch.Index.ToString & ""
Next
lblNumber.Text = mchs.Count.ToString & " matches found"
Catch ex As Exception
lstMatches.Items.Add(ex.Message)
End Try
End Sub
Private Sub txtSource_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSource.TextChanged
Call MyExecute()
End Sub
Private Sub txtPattern_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPattern.TextChanged
Call MyExecute()
End Sub
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class