Categorymvdan.cc/xurls/v2
modulepackage
2.6.0
Repository: https://github.com/mvdan/xurls.git
Documentation: pkg.go.dev

# README

xurls

Go Reference

Extract urls from text using regular expressions. Requires Go 1.22 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.

The regular expressions are compiled when the API is first called. Any subsequent calls will use the same regular expression pointers.

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

# Packages

No description provided by the author
No description provided by the author

# Functions

Relaxed produces a regexp that matches any URL matched by Strict, plus any URL or email address with no scheme.
Strict produces a regexp that matches any URL with a scheme in either the Schemes or SchemesNoAuthority lists.
StrictMatchingScheme produces a regexp similar to Strict, but requiring that the scheme match the given regular expression.

# Variables

AnyScheme can be passed to StrictMatchingScheme to match any possibly valid scheme, and not just the known ones.
PseudoTLDs is a sorted list of some widely used unofficial TLDs.
Schemes is a sorted list of all IANA assigned schemes.
SchemesNoAuthority is a sorted list of some well-known url schemes that are followed by ":" instead of "://".
SchemesUnofficial is a sorted list of some well-known url schemes which aren't officially registered just yet.
TLDs is a sorted list of all public top-level domains.