Imports System
Imports System.Text.RegularExpressions
Imports System.Collections.Generic
Class Program
Public Shared Sub Main()
Dim input As String = "This is a [sample] string with [multiple] square brackets."
Dim extracted = ExtractBracketedContent(input)
For Each item In extracted
Console.WriteLine(item)
Next
End Sub
Private Shared Function ExtractBracketedContent(ByVal text As String) As List(Of String)
Dim pattern As String = "\[(.*?)\]"
Dim matches As MatchCollection = Regex.Matches(text, pattern)
Dim result = New List(Of String)()
For Each match As Match In matches
result.Add(match.Groups(1).Value)
Next
Return result
End Function
End Class
' run:
'
' sample
' multiple
'