Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding multiple occurances of a reg exp pattern 1

Status
Not open for further replies.

kristof

Programmer
Jun 2, 2000
234
BE
Hi,

Suppose I have a string like: (A)((B)(C))

I need a pattern that looks for strings within ( and ), so that should return:
(A)
((B) (C))
(B)
(C)

This is the code I have now, but I have no idea about what pattern can do that:
Code:
Dim oRegExp As New System.Text.RegularExpressions.Regex(txtPattern.Text)
Dim m As System.Text.RegularExpressions.Match = oRegExp.Match(txtText.Text)

rtbResults.Text = ""
For i As Integer = 0 To m.Captures.Count - 1
	sText += m.Captures(i).Value & vbCrLf
Next

Thanks
 
Well, this was my brain exercise for today! Hope this is appreciated ;)

Just paste in and call the following method:

Code:
Private Sub Match(ByVal source As String)
        Dim pattern As String = "(((?'pos'\() [^()]*)+((?'pos2-pos'\))[^()]*)+)+"
        Dim match As Match = System.Text.RegularExpressions.Regex.Match(source, pattern, RegexOptions.IgnorePatternWhitespace Or RegexOptions.ExplicitCapture)
        If match.Success Then
            For Each capture As Capture In match.Groups("pos2").Captures
                'could add to an array instead, etc here
                MsgBox("(" & capture.Value & ")")
            Next
        End If
    End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top