package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?<!=\")\b((?:http|https|ftp):\/\/)((?:(?:\w)+\.)+(?:\w)+)(:\d+)?((?:\/[\w]+)*[.\w]*\/?)((?:[\?\w\=\_\-%+!$^*\/\\@#;:]|(?:&(?!gt;)|(?:['"](?=[\w"'&#,]))))*)`)
var str = `<http://www.google.com.edu:8080/path/to/ting.this?this=that&that=this#21>
<http://www.google.com/path/to/thing/?this=that&that=this#21>
http://google.com
https://www.yy.sdf.yahoo.com.sdf.s.dsf.cat/
"ftp://msn.com/path.thing"
'http://askdeeves.com/sdf?asdf="sdf"&cat=blue'
<http://ask.com#21>
href="http://askdeeves.com/sdf?asdf="sdf"&cat=blue"
`
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/