How to make the RegEx below ignore only the first instance it finds for this characte

piscis

Well-known member
Joined
Jun 30, 2003
Messages
54
Code:
How to make the RegEx below ignore only the first instance it finds for this character " = " and continue with the rest of the file.


            Dim MyRegEx As New Regex("=\s+(?<MyPat>[0-9]*[\+.]*[0-9]*)")
            Dim s As String = txtDataView.Text
            Dim Mc As MatchCollection = MyRegEx.Matches(s)
            Dim M As Match
            Dim i As Integer
            If Mc.Count > 0 Then
                i = 0
                For Each M In Mc
                    i += 1
                    PutInTextBox(Me, "TextBox" & CStr(i), M.Groups("MyPat").Value)
                Next

Private Sub PutInTextBox(ByVal ContainerCtrl As Control, ByVal TBName As String, ByVal msg As String)
        Dim ctl As Control
        For Each ctl In ContainerCtrl.Controls
            If TypeOf ctl Is TextBox And ctl.Name = TBName Then
                ctl.Text = msg
                Exit For
            Else
                PutInTextBox(ctl, TBName, msg)
            End If
        Next
    End Sub
 
you could omit the first match, when putting the found values into the textboxes... like this:

[VB]Dim MyRegEx As New Regex("=\s+(?<MyPat>[0-9]*[\+.]*[0-9]*)")
Dim s As String = txtDataView.Text
Dim Mc As MatchCollection = MyRegEx.Matches(s)
Dim M As Match
Dim i As Integer
If Mc.Count > 0 Then
i = 0
For Each M In Mc
i += 1
If Not i = 1 Then
PutInTextBox(Me, "TextBox" & CStr(i), M.Groups("MyPat").Value)
End If
Next
End If
[/VB]

Or you extend the pattern to this:
".*=.*=\s+(?<MyPat>[0-9]*[\+.]*[0-9]*)"

now it only matches if theres a "=" before the "=" you want to match... e.g. the first one is omitted...

Hope this helps!

Andreas
 
Back
Top