package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^https:\/\/(?:www\.)?kuula.co\/share\/(?:[A-Za-z0-9]+\/)?(?:collection\/)?([A-Za-z0-9]+)(\?.*)?$`)
var str = `https://kuula.co
https://kuula.co/about
https://kuula.co/post
https://kuula.co/share
https://kuula.co/share/39u4$
https://kuula.co/post/7qQZ7
https://kuula.co/post/7qQZ7/collection/7lPZ8
http://kuula.co/share/7qQZ7
https://kuula.co/share/7qQZ7
https://kuula.co/share/collection/7lPZ8
https://kuula.co/share/7qQZ7?fs=1&abc=10
https://kuula.co/share/7qQZ7/collection/7lPZ8
https://kuula.co/share/collection/7lPZ8?vr=0
https://www.kuula.co/share/7qQZ7?abc=1
https://another-page.net/share/7qQZ7
https://kuula.co.another-page.com/share/7qQZ7`
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/