You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
844 B

  1. # xurls
  2. [![GoDoc](https://godoc.org/mvdan.cc/xurls?status.svg)](https://godoc.org/mvdan.cc/xurls)
  3. Extract urls from text using regular expressions. Requires Go 1.12 or later.
  4. ```go
  5. import "mvdan.cc/xurls/v2"
  6. func main() {
  7. rxRelaxed := xurls.Relaxed()
  8. rxRelaxed.FindString("Do gophers live in golang.org?") // "golang.org"
  9. rxRelaxed.FindString("This string does not have a URL") // ""
  10. rxStrict := xurls.Strict()
  11. rxStrict.FindAllString("must have scheme: http://foo.com/.", -1) // []string{"http://foo.com/"}
  12. rxStrict.FindAllString("no scheme, no match: foo.com", -1) // []string{}
  13. }
  14. ```
  15. Note that the funcs compile regexes, so avoid calling them repeatedly.
  16. #### cmd/xurls
  17. To install the tool globally:
  18. go get mvdan.cc/xurls/cmd/xurls
  19. ```shell
  20. $ echo "Do gophers live in http://golang.org?" | xurls
  21. http://golang.org
  22. ```