Read the contents of a textbox and look for a pattern match, then execute a series of events when (or if) that pattern is found.
That much I have accomplished, but how do I get the program to look for other instances of that pattern within the same textbox.
For instance, suppose the program finds a match at index 0 in the textbox, then executes its series of events. How do I get a recursion
of the text while ignoring the text section previously covered.
Imports SpeechLib
Imports System.Text.RegularExpressions
Public Class Form1
Dim compVoice As New SpVoice
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim regex As Regex = New Regex("^\d\d:\d\d")
Dim td As DateTime = DateTime.Now()
If CInt(TextBox1.Text) = td.Day Then
'run textbox1 here.
If regex.IsMatch(txtDay1.Text, 0) Then
compVoice.Volume = 100
compVoice.Speak("Warning")
compVoice.Volume = 50
compVoice.Speak(txtDay1.Text.Substring(6))
Else
compVoice.Speak("No text present.")
End If
ElseIf CInt(TextBox2.Text) = td.Day Then
'run textbox2 here
If regex.IsMatch(txtDay2.Text, 0) Then
compVoice.Volume = 100
compVoice.Speak("Warning")
compVoice.Volume = 50
compVoice.Speak(txtDay2.Text.Substring(6))
Else
compVoice.Speak("No text present.")
End If
ElseIf CInt(TextBox3.Text) = td.Day Then
If regex.IsMatch(txtDay3.Text, 0) Then
compVoice.Volume = 100
compVoice.Speak("Warning")
compVoice.Volume = 50
compVoice.Speak(txtDay3.Text.Substring(6))
Else
compVoice.Speak("No text present.")
End If
Else
Exit Sub
End If
End Sub
End Class
VulpesPosted Feb 16, 2013, 4:15 PM
http://msdn.microsoft.com/en-us/library/twcw2f1c.aspx
Notice that you can also use the Match object's NextMatch method to find the next match or get all matches at once with the Regex.Matches method. However, if the first match has to be at the beginning of the string, then they will be awkward to use because of the need to change the Regex after the first match. One thing you could do though would be to use "\d\d:\d\d" throughout and just check that the first match is at index 0.