Help us shape the future of Go! Take the 2026 Go Developer Survey

xurls

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2015 License: BSD-3-Clause Imports: 1 Imported by: 375

README

xurls

Extract urls from plain text using regular expressions.

go get github.com/mvdan/xurls

Example usage:

import "github.com/mvdan/xurls"

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

This is not a URL validation library. Extracted urls may well not be valid.

Command-line utilities
xurls

Reads text and prints one url per line.

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Relaxed matches all the urls it can find
	Relaxed = regexp.MustCompile(relaxed)
	// Strict only matches urls with a scheme to avoid false positives
	Strict = regexp.MustCompile(strict)
)
View Source
var PseudoTLDs = []string{
	`bit`,
	`exit`,
	`i2p`,
	`local`,
	`onion`,
}

PseudoTLDs is a sorted list of some widely used unofficial TLDs

Sources:

View Source
var TLDs = []string{}/* 1208 elements not displayed */

TLDs is a sorted list of all public top-level domains

Sources:

Functions

func StrictMatching added in v0.4.0

func StrictMatching(schemeExp string) *regexp.Regexp

StrictMatching matches urls like Strict but matching a specified scheme regular expression

Types

This section is empty.

Directories

Path Synopsis
cmd
xurls command
tools
regexgen command
tldsgen command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL