package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(Sent|Received).*?(\d.*?(?:AM|PM))\s(?:to\s|from\s)(\w*?)\n\n([\s\S]*?)(?:\n\-{5}|$)[\n\S\s]*?`)
var str = `Sent on 1/1/2023 7:30:33 AM to Person1
Message
-----
Received on 5/20/2023 4:55:33 PM from Person1
Message`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/