xurls – github.com/mvdan/xurls Index | Examples | Files | Directories

package xurls

import "github.com/mvdan/xurls"

Package xurls extracts urls from plain text using regular expressions.

Example

Code:play 

package main

import (
	"fmt"

	"github.com/mvdan/xurls"
)

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

Output:

http://golang.org
[foo.com http://foo.com/]

Index

Examples

Variables

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)
)
var PseudoTLDs = []string{
	`bit`,
	`example`,
	`exit`,
	`gnu`,
	`i2p`,
	`invalid`,
	`local`,
	`localhost`,
	`test`,
	`zkey`,
}

PseudoTLDs is a sorted list of some widely used unofficial TLDs.

Sources:

var SchemesNoAuthority = []string{
	`bitcoin`,
	`file`,
	`magnet`,
	`mailto`,
	`sms`,
	`tel`,
	`xmpp`,
}

SchemesNoAuthority is a sorted list of some well-known url schemes that are followed by ":" instead of "://". Since these are more prone to false positives, we limit their matching.

var TLDs = []string{ /* 1554 elements not displayed */

}

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

Sources:

Functions

func StrictMatchingScheme

func StrictMatchingScheme(exp string) (*regexp.Regexp, error)

StrictMatchingScheme produces a regexp that matches urls like Strict but whose scheme matches the given regular expression.

Source Files

regex.go schemes.go tlds.go tlds_pseudo.go xurls.go

Directories

PathSynopsis
cmd
cmd/xurls
generate
generate/regexgen
generate/tldsgen
Version
v1.1.0 (latest)
Published
Jan 25, 2017
Platform
linux/amd64
Imports
1 packages
Last checked
2 weeks ago

Tools for package owners.