Skip to content

Commit

Permalink
README: use a better example
Browse files Browse the repository at this point in the history
Some users were repeating the regexp compile, so make that more obvious.
Thanks to Kevin Burke for the idea.

While at it, update the go.mod language version.

Fixes #31.
  • Loading branch information
mvdan committed Sep 22, 2019
1 parent 0ca2609 commit e21d637
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ Extract urls from text using regular expressions. Requires Go 1.12 or later.
import "mvdan.cc/xurls/v2"

func main() {
xurls.Relaxed().FindString("Do gophers live in golang.org?")
// "golang.org"
xurls.Strict().FindAllString("foo.com is http://foo.com/.", -1)
// []string{"http://foo.com/"}
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{}
}
```

Expand All @@ -21,7 +24,7 @@ Note that the funcs compile regexes, so avoid calling them repeatedly.

To install the tool globally:

go get -u mvdan.cc/xurls/cmd/xurls
go get mvdan.cc/xurls/cmd/xurls

```shell
$ echo "Do gophers live in http://golang.org?" | xurls
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module mvdan.cc/xurls/v2

go 1.10
go 1.13

0 comments on commit e21d637

Please sign in to comment.