package main
import (
"fmt"
"regexp"
)
func extractBracketedContent(text string) []string {
pattern := regexp.MustCompile(`\[(.*?)\]`)
matches := pattern.FindAllStringSubmatch(text, -1)
var results []string
for _, match := range matches {
if len(match) > 1 {
results = append(results, match[1]) // Captured group inside brackets
}
}
return results
}
func main() {
input := "This is a [sample] string with [multiple] square brackets."
extracted := extractBracketedContent(input)
for _, item := range extracted {
fmt.Println(item)
}
}
/*
run:
sample
multiple
*/