package main
import (
"fmt"
"regexp"
)
func main() {
str := `This is a string with "double-quoted substring1", and "double-quoted substring2" inside.`
// Regular expression pattern to match substrings within double quotes
pattern := regexp.MustCompile(`"([^"]*)"`)
// Find all matches
matches := pattern.FindAllStringSubmatch(str, -1)
// Extract substrings
var substrings []string
for _, match := range matches {
substrings = append(substrings, match[1])
}
fmt.Println(substrings)
// Print each extracted substring using a loop
for _, match := range matches {
fmt.Println(match[1])
}
}
/*
run:
[double-quoted substring1 double-quoted substring2]
double-quoted substring1
double-quoted substring2
*/