Skip to content
Extract urls from text
Branch: master
Clone or download
Latest commit b13bca4 Dec 28, 2019



Extract urls from text using regular expressions. Requires Go 1.12 or later.

import ""

func main() {
	rxRelaxed := xurls.Relaxed()
	rxRelaxed.FindString("Do gophers live in")  // ""
	rxRelaxed.FindString("This string does not have a URL") // ""

	rxStrict := xurls.Strict()
	rxStrict.FindAllString("must have scheme:", -1) // []string{""}
	rxStrict.FindAllString("no scheme, no match:", -1)       // []string{}

Note that the funcs compile regexes, so avoid calling them repeatedly.


To install the tool globally:

cd $(mktemp -d); go mod init tmp; GO111MODULE=on go get
$ echo "Do gophers live in" | xurls
You can’t perform that action at this time.