go-common/vendor/github.com/mvdan/xurls
MiaoWoo fc4fa37393 Create & Init Project... 2019-04-22 18:49:16 +08:00
..
BUILD.bazel Create & Init Project... 2019-04-22 18:49:16 +08:00
LICENSE Create & Init Project... 2019-04-22 18:49:16 +08:00
README.md Create & Init Project... 2019-04-22 18:49:16 +08:00
regex.go Create & Init Project... 2019-04-22 18:49:16 +08:00
schemes.go Create & Init Project... 2019-04-22 18:49:16 +08:00
tlds.go Create & Init Project... 2019-04-22 18:49:16 +08:00
tlds_pseudo.go Create & Init Project... 2019-04-22 18:49:16 +08:00
xurls.go Create & Init Project... 2019-04-22 18:49:16 +08:00

README.md

xurls

GoDoc Travis

Extract urls from text using regular expressions.

go get -u github.com/mvdan/xurls
import "github.com/mvdan/xurls"

func main() {
	xurls.Relaxed.FindString("Do gophers live in golang.org?")
	// "golang.org"
	xurls.Strict.FindAllString("foo.com is http://foo.com/.", -1)
	// []string{"http://foo.com/"}
}

Relaxed is around five times slower than Strict since it does more work to find the URLs without relying on the scheme:

BenchmarkStrictEmpty-4           1000000              1885 ns/op
BenchmarkStrictSingle-4           200000              8356 ns/op
BenchmarkStrictMany-4             100000             22547 ns/op
BenchmarkRelaxedEmpty-4           200000              7284 ns/op
BenchmarkRelaxedSingle-4           30000             58557 ns/op
BenchmarkRelaxedMany-4             10000            130251 ns/op

cmd/xurls

go get -u github.com/mvdan/xurls/cmd/xurls
$ echo "Do gophers live in http://golang.org?" | xurls
http://golang.org