E.g.
vb.net Code:
  1. Dim findStartIndex = 0
  2. Dim openingChars = {"<"c, "("c, "{"c, "["c}
  3. Dim closingChars = {">"c, ")"c, "}"c, "]"c}
  4.  
  5. Do
  6.     'Find the start of the next substring.
  7.     Dim substringStartIndex = RichTextBox1.Find(openingChars, findStartIndex)
  8.  
  9.     If substringStartIndex = -1 Then
  10.         'No more substrings to find.
  11.         Exit Do
  12.     End If
  13.  
  14.     Dim openingChar = RichTextBox1.Text(substringStartIndex)
  15.     Dim closingChar = closingChars(Array.IndexOf(openingChars, openingChar))
  16.  
  17.     'Find the end of the current substring.
  18.     Dim substringEndIndex = RichTextBox1.Find({closingChar}, substringStartIndex + 1)
  19.  
  20.     'Use substringStartIndex and substringEndIndex here.
  21.  
  22.     'The next search starts after the current substring.
  23.     findStartIndex = substringEndIndex + 1
  24. Loop