package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)^(https?:\/\/)?([\w\Q$-_+!*'(),%\E]+\.)+(\w{2,63})(:\d{1,4})?([\w\Q/$-_+!*'(),%\E]+\.?[\w])*\/?$`)
var str = `http://google.com
https://google.com
http://www.google.com
www.google.com
www.google.de:8080
www.test123.de
www.domain.com.de.whatever.to
www.google
h4xx0!2.net
page.to
hallo.to/test/whatever
hallo.to/test/whatever.cgi
www.google.com/startpage.html/
www.google.!!!
www..com
http://blabla.computer.de/.......................`
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/