package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`http(?:s)?:\/\/(?:www\.)?youtube\.com\/.*?watch%3Fv%([\d\w-_]+)`)
var str = `http://youtube.com/attribution_link?a=r_FgjB-RKNo&u=/watch%3Fv%3DB0_X8zWJd0Q%26feature%3Dem-uploademail
http://youtube.com/attribution_link?a=1crTn2Lx38I&u=/watch%3Fv%3DHhebhh2s5d4%26feature%3Dem-uploademail
http://youtube.com/attribution_link?a=_zMgiznzBto&u=/watch%3Fv%3D-kaoCPvUHJM%26feature%3Dem-uploademail
http://youtube.com/attribution_link?a=F8VReY1sT0A&u=/watch%3Fv%3D5RLM9rk0Q8s%26feature%3Dem-uploademail
https://www.youtube.com/watch?feature=player_detailpage&v=2eGUP16P_p4
`
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/