Skip to content
master
Switch branches/tags
Code

Latest commit

Add gemini:// and moz-extension:// schemes.

moz-extension:// is used by Firefox addons. People using FF devtools
frequently end up copying moz-extension URLs, so it might make sense to
include their scheme.

gemini:// is a new protocol for a network that sits somewhere between
Gopher and the WWW. Although not registered with the IANA yet, it does
have an acative community that shares a lot of gemini:// links in various
places. xurls should recognize these. More info at
https://gemini.circumlunar.space and gemini://gemini.circumlunar.space.
2c03c21

Git stats

Files

Permalink
Failed to load latest commit information.

xurls

Go Reference

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

import "mvdan.cc/xurls/v2"

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

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

Since API is centered around regexp.Regexp, many other methods are available, such as finding the byte indexes for all matches.

Note that calling the exposed functions means compiling a regular expression, so repeated calls should be avoided.

cmd/xurls

To install the tool globally:

go install mvdan.cc/xurls/v2/cmd/xurls@latest
$ echo "Do gophers live in http://golang.org?" | xurls
http://golang.org