forked from mvdan/xurls
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
44 lines (38 loc) · 1.02 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) 2015, Daniel Martí <mvdan@mvdan.cc>
// See LICENSE for licensing information
package xurls_test
import (
"fmt"
"mvdan.cc/xurls/v2"
)
func Example() {
rx := xurls.Relaxed()
fmt.Println(rx.FindString("Do gophers live in http://golang.org?"))
fmt.Println(rx.FindAllString("foo.com is http://foo.com/.", -1))
// Output:
// http://golang.org
// [foo.com http://foo.com/]
}
func ExampleStrictMatchingScheme() {
rx, err := xurls.StrictMatchingScheme(`https?://`)
if err != nil {
panic(err)
}
fmt.Println(rx.FindAllString("Download binaries via https://foo.com/dl or ftps://foo.com/dl", -1))
// Output:
// [https://foo.com/dl]
}
func Example_filterEmails() {
s := "Email dev@foo.com about any issues with foo.com or https://foo.com/dl"
rx := xurls.Relaxed()
idxEmail := rx.SubexpIndex("relaxedEmail")
for _, match := range rx.FindAllStringSubmatch(s, -1) {
if match[idxEmail] != "" {
continue // skip lone email addresses
}
fmt.Println(match[0])
}
// Output:
// foo.com
// https://foo.com/dl
}