fork download
  1. Imports System
  2. Imports System.Text.RegularExpressions
  3.  
  4. Public Class Test
  5. Public Shared Sub Main()
  6. Dim i As Integer
  7. Dim pattern As String = "(?<=\()[a-z]+(?=\((?:\((\d+)\))?(?:\((\d+)\))?\))"
  8. Dim text As String = "(abc())(def((123)(456))(klm((123))"
  9. Dim matches As MatchCollection = System.Text.RegularExpressions.Regex.Matches(text, pattern)
  10. For Each m As Match In matches
  11. i = 0
  12. For Each g As Group in m.Groups
  13. If i = 0 Then
  14. Console.WriteLine("Match: " & g.Value)
  15. ElseIf i > 0 and g.Value <> "" Then
  16. Console.WriteLine("Group " & i & ": " & g.Value)
  17. End If
  18. i = i + 1
  19. Next
  20. Next
  21. End Sub
  22. End Class
Success #stdin #stdout 0.09s 34628KB
stdin
stdout
Match: abc
Match: def
Group 1: 123
Group 2: 456
Match: klm
Group 1: 123