-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshared_test.go
47 lines (42 loc) · 1.13 KB
/
shared_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
45
46
47
package regexer_test
import (
"fmt"
"github.com/orsinium-labs/regexer"
)
func ExampleSubs_At() {
rex := regexer.New(`([a-z.]+)@([a-z.]+)`)
input := "my email is mail@example.com, text me"
matches := rex.String(input).Find()
for match := range matches {
username := match.Subs.At(1).Content
domain := match.Subs.At(2).Content
fmt.Printf("username: %s; domain: %s", username, domain)
}
//Output: username: mail; domain: example.com
}
func ExampleSubs_Slice() {
rex := regexer.New(`([a-z.]+)@([a-z.]+)`)
input := "my email is mail@example.com, text me"
matches := rex.String(input).Find()
for match := range matches {
subs := match.Subs.Slice()
username := subs[1].Content
domain := subs[2].Content
fmt.Printf("username: %s; domain: %s", username, domain)
}
//Output: username: mail; domain: example.com
}
func ExampleSubs_Iter() {
rex := regexer.New(`([a-z.]+)@([a-z.]+)`)
input := "my email is mail@example.com, text me"
matches := rex.String(input).Find()
for match := range matches {
for sub := range match.Subs.Iter() {
fmt.Println(sub.Content)
}
}
//Output:
// mail@example.com
// mail
// example.com
}