最近学习一下正则,顺便把书里的例子抄袭一下。^ ^ ...
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions


Public Class Form1Class Form1
Inherits System.Windows.Forms.Form


Windows 窗体设计器生成的代码#Region " Windows 窗体设计器生成的代码 "


Public Sub New()Sub New()
MyBase.New()

'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写 dispose 以清理组件列表。

Protected Overloads Overrides Sub Dispose()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

'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer

'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents cmdTestRegex As System.Windows.Forms.Button
Friend WithEvents cmdReplace As System.Windows.Forms.Button
Friend WithEvents cmdMatches As System.Windows.Forms.Button
Friend WithEvents cmdSplit As System.Windows.Forms.Button
Friend WithEvents cmdOpenRegex As System.Windows.Forms.Button
Friend WithEvents cmdSaveRegex As System.Windows.Forms.Button
Friend WithEvents grpOptions As System.Windows.Forms.GroupBox
Friend WithEvents chkSingleLine As System.Windows.Forms.CheckBox
Friend WithEvents chkRightToLeft As System.Windows.Forms.CheckBox
Friend WithEvents chkMultiLine As System.Windows.Forms.CheckBox
Friend WithEvents chkIgnorePatternWhiteSpace As System.Windows.Forms.CheckBox
Friend WithEvents chkIgnoreCase As System.Windows.Forms.CheckBox
Friend WithEvents chkExplicitCapture As System.Windows.Forms.CheckBox
Friend WithEvents chkECMAScript As System.Windows.Forms.CheckBox
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
Friend WithEvents txtResults As System.Windows.Forms.TextBox
Friend WithEvents txtReplacementText As System.Windows.Forms.TextBox
Friend WithEvents txtRegex As System.Windows.Forms.TextBox
Friend WithEvents txtInputText As System.Windows.Forms.TextBox

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label
Me.txtRegex = New System.Windows.Forms.TextBox
Me.grpOptions = New System.Windows.Forms.GroupBox
Me.chkIgnorePatternWhiteSpace = New System.Windows.Forms.CheckBox
Me.chkECMAScript = New System.Windows.Forms.CheckBox
Me.chkExplicitCapture = New System.Windows.Forms.CheckBox
Me.chkIgnoreCase = New System.Windows.Forms.CheckBox
Me.chkMultiLine = New System.Windows.Forms.CheckBox
Me.chkRightToLeft = New System.Windows.Forms.CheckBox
Me.chkSingleLine = New System.Windows.Forms.CheckBox
Me.cmdOpenRegex = New System.Windows.Forms.Button
Me.cmdSaveRegex = New System.Windows.Forms.Button
Me.Label2 = New System.Windows.Forms.Label
Me.txtInputText = New System.Windows.Forms.TextBox
Me.txtReplacementText = New System.Windows.Forms.TextBox
Me.Label3 = New System.Windows.Forms.Label
Me.txtResults = New System.Windows.Forms.TextBox
Me.Label4 = New System.Windows.Forms.Label
Me.cmdReplace = New System.Windows.Forms.Button
Me.cmdTestRegex = New System.Windows.Forms.Button
Me.cmdMatches = New System.Windows.Forms.Button
Me.cmdSplit = New System.Windows.Forms.Button
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
Me.grpOptions.SuspendLayout()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(8, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(144, 23)
Me.Label1.TabIndex = 0
Me.Label1.Text = "Regular Expression"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.BottomLeft
'
'txtRegex
'
Me.txtRegex.Location = New System.Drawing.Point(8, 32)
Me.txtRegex.Multiline = True
Me.txtRegex.Name = "txtRegex"
Me.txtRegex.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtRegex.Size = New System.Drawing.Size(472, 48)
Me.txtRegex.TabIndex = 1
Me.txtRegex.Text = ""
'
'grpOptions
'
Me.grpOptions.Controls.Add(Me.chkIgnorePatternWhiteSpace)
Me.grpOptions.Controls.Add(Me.chkECMAScript)
Me.grpOptions.Controls.Add(Me.chkExplicitCapture)
Me.grpOptions.Controls.Add(Me.chkIgnoreCase)
Me.grpOptions.Controls.Add(Me.chkMultiLine)
Me.grpOptions.Controls.Add(Me.chkRightToLeft)
Me.grpOptions.Controls.Add(Me.chkSingleLine)
Me.grpOptions.Location = New System.Drawing.Point(8, 80)
Me.grpOptions.Name = "grpOptions"
Me.grpOptions.Size = New System.Drawing.Size(304, 112)
Me.grpOptions.TabIndex = 2
Me.grpOptions.TabStop = False
Me.grpOptions.Text = "Regex Options"
'
'chkIgnorePatternWhiteSpace
'
Me.chkIgnorePatternWhiteSpace.Location = New System.Drawing.Point(8, 72)
Me.chkIgnorePatternWhiteSpace.Name = "chkIgnorePatternWhiteSpace"
Me.chkIgnorePatternWhiteSpace.Size = New System.Drawing.Size(184, 24)
Me.chkIgnorePatternWhiteSpace.TabIndex = 6
Me.chkIgnorePatternWhiteSpace.Text = "IgnorePatternWhiteSpace"
'
'chkECMAScript
'
Me.chkECMAScript.Location = New System.Drawing.Point(200, 44)
Me.chkECMAScript.Name = "chkECMAScript"
Me.chkECMAScript.Size = New System.Drawing.Size(88, 24)
Me.chkECMAScript.TabIndex = 5
Me.chkECMAScript.Text = "ECMAScript"
'
'chkExplicitCapture
'
Me.chkExplicitCapture.Location = New System.Drawing.Point(96, 44)
Me.chkExplicitCapture.Name = "chkExplicitCapture"
Me.chkExplicitCapture.TabIndex = 4
Me.chkExplicitCapture.Text = "ExplicitCapture"
'
'chkIgnoreCase
'
Me.chkIgnoreCase.Location = New System.Drawing.Point(8, 44)
Me.chkIgnoreCase.Name = "chkIgnoreCase"
Me.chkIgnoreCase.TabIndex = 3
Me.chkIgnoreCase.Text = "IgnoreCase"
'
'chkMultiLine
'
Me.chkMultiLine.Location = New System.Drawing.Point(200, 16)
Me.chkMultiLine.Name = "chkMultiLine"
Me.chkMultiLine.Size = New System.Drawing.Size(88, 24)
Me.chkMultiLine.TabIndex = 2
Me.chkMultiLine.Text = "MultiLine"
'
'chkRightToLeft
'
Me.chkRightToLeft.Location = New System.Drawing.Point(96, 16)
Me.chkRightToLeft.Name = "chkRightToLeft"
Me.chkRightToLeft.TabIndex = 1
Me.chkRightToLeft.Text = "RightToLeft"
'
'chkSingleLine
'
Me.chkSingleLine.Location = New System.Drawing.Point(8, 16)
Me.chkSingleLine.Name = "chkSingleLine"
Me.chkSingleLine.TabIndex = 0
Me.chkSingleLine.Text = "SingleLine"
'
'cmdOpenRegex
'
Me.cmdOpenRegex.Location = New System.Drawing.Point(320, 88)
Me.cmdOpenRegex.Name = "cmdOpenRegex"
Me.cmdOpenRegex.TabIndex = 3
Me.cmdOpenRegex.Text = "OpenRegex"
'
'cmdSaveRegex
'
Me.cmdSaveRegex.Location = New System.Drawing.Point(408, 88)
Me.cmdSaveRegex.Name = "cmdSaveRegex"
Me.cmdSaveRegex.TabIndex = 4
Me.cmdSaveRegex.Text = "SaveRegex"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(8, 200)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(112, 23)
Me.Label2.TabIndex = 5
Me.Label2.Text = "Text to Match on"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.BottomLeft
'
'txtInputText
'
Me.txtInputText.Location = New System.Drawing.Point(9, 224)
Me.txtInputText.Multiline = True
Me.txtInputText.Name = "txtInputText"
Me.txtInputText.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtInputText.Size = New System.Drawing.Size(471, 48)
Me.txtInputText.TabIndex = 6
Me.txtInputText.Text = ""
'
'txtReplacementText
'
Me.txtReplacementText.Location = New System.Drawing.Point(10, 304)
Me.txtReplacementText.Multiline = True
Me.txtReplacementText.Name = "txtReplacementText"
Me.txtReplacementText.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtReplacementText.Size = New System.Drawing.Size(470, 32)
Me.txtReplacementText.TabIndex = 8
Me.txtReplacementText.Text = ""
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(9, 280)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(111, 23)
Me.Label3.TabIndex = 7
Me.Label3.Text = "ReplacementText"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.BottomLeft
'
'txtResults
'
Me.txtResults.Location = New System.Drawing.Point(10, 360)
Me.txtResults.Multiline = True
Me.txtResults.Name = "txtResults"
Me.txtResults.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.txtResults.Size = New System.Drawing.Size(470, 64)
Me.txtResults.TabIndex = 10
Me.txtResults.Text = ""
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(9, 336)
Me.Label4.Name = "Label4"
Me.Label4.TabIndex = 9
Me.Label4.Text = "Results of Match"
Me.Label4.TextAlign = System.Drawing.ContentAlignment.BottomLeft
'
'cmdReplace
'
Me.cmdReplace.Location = New System.Drawing.Point(104, 432)
Me.cmdReplace.Name = "cmdReplace"
Me.cmdReplace.TabIndex = 12
Me.cmdReplace.Text = "Replace()"
'
'cmdTestRegex
'
Me.cmdTestRegex.Location = New System.Drawing.Point(16, 432)
Me.cmdTestRegex.Name = "cmdTestRegex"
Me.cmdTestRegex.TabIndex = 11
Me.cmdTestRegex.Text = "IsMatch()"
'
'cmdMatches
'
Me.cmdMatches.Location = New System.Drawing.Point(280, 432)
Me.cmdMatches.Name = "cmdMatches"
Me.cmdMatches.TabIndex = 14
Me.cmdMatches.Text = "Matches()"
'
'cmdSplit
'
Me.cmdSplit.Location = New System.Drawing.Point(192, 432)
Me.cmdSplit.Name = "cmdSplit"
Me.cmdSplit.TabIndex = 13
Me.cmdSplit.Text = "Split()"
'
'OpenFileDialog1
'
'
'SaveFileDialog1
'
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
Me.ClientSize = New System.Drawing.Size(492, 466)
Me.Controls.Add(Me.cmdMatches)
Me.Controls.Add(Me.cmdSplit)
Me.Controls.Add(Me.cmdReplace)
Me.Controls.Add(Me.cmdTestRegex)
Me.Controls.Add(Me.txtResults)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.txtReplacementText)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.txtInputText)