项目作者: mvdan

项目描述 :
Extract urls from text
高级语言: Go
项目地址: git://github.com/mvdan/xurls.git
创建时间: 2015-01-12T01:28:46Z
项目社区:https://github.com/mvdan/xurls

开源协议:BSD 3-Clause "New" or "Revised" License

下载


xurls

Go Reference

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

  1. import "mvdan.cc/xurls/v2"
  2. func main() {
  3. rxRelaxed := xurls.Relaxed()
  4. rxRelaxed.FindString("Do gophers live in golang.org?") // "golang.org"
  5. rxRelaxed.FindString("This string does not have a URL") // ""
  6. rxStrict := xurls.Strict()
  7. rxStrict.FindAllString("must have scheme: http://foo.com/.", -1) // []string{"http://foo.com/"}
  8. rxStrict.FindAllString("no scheme, no match: foo.com", -1) // []string{}
  9. }

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:

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