package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?im)^(?:https?:\/\/)?(?:(?:[\pL0-9-]+)\.)+[\pL]{2,}(?:\/.*)?$`)
var str = `http://google.com
https://google.com
http://google.com/
https://google.com/
http://g oogle.com
http://google.com/somepath
https://g oogle.com/somepath
https://g_oogle.com/somepath
google.com
google.com/somepath
goo gle.com/badpath
кириллица.укр
кирилл ица.укр
кириллица.укр/путь
кирилл01ица.укр
кирилли-ца.укр/путь
собдомен.кириллица.укр
собдомен.кириллица.укр/путь
2саб.1саб.домен.укр
2саб.1с-аб.до мен.укр`
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/