package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`((?:\/[A-Za-z0-9-]+)+)?(\/tag\/[A-Za-z0-9-%]+)+(\/.*)?`)
var str = `http://example.com/cat1/subcat3/subcat4/tag/this%20is%20page/asdasda?start=130/asdasdasd
http://example.com/cat1/subcat3/subcat4/tag/this%20is%20pageasdasd
example.it/news/tag/this%is%20n%page?adsadsadasd
http://example.com/tag/thispage/asdasdasd.-?asds=
http://example.com/tag/this%20is%20page/asdasd
http://example.com/tag/this
`
var substitution = "$2"
fmt.Println(re.ReplaceAllString(str, substitution))
}
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/