-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstreamregexdoc_test.go
More file actions
47 lines (38 loc) · 992 Bytes
/
streamregexdoc_test.go
File metadata and controls
47 lines (38 loc) · 992 Bytes
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 streamregex
import (
"context"
"fmt"
"regexp"
"strings"
)
func ExampleFindReader() {
// Create string
data := `0123456789this is a stream of data with lots of trailing information`
stream := strings.NewReader(data)
// Build regex
regex := regexp.MustCompile(`stream\s+of`)
// Find matches
matchedData := FindReader(context.Background(), regex, 100, stream)
matches := 0
for match := range matchedData {
matches++
fmt.Println(match)
}
// Output: stream of
}
func ExampleFindReaderIndex() {
// Create string
data := `0123456789this is a stream of data with lots of trailing information`
stream := strings.NewReader(data)
// Build regex
regex := regexp.MustCompile(`stream\s+of`)
// Find matches and indexes
matchedData, matchedIndexes := FindReaderIndex(context.Background(), regex, 100, stream)
matches := 0
for match := range matchedData {
index := <-matchedIndexes
matches++
fmt.Println(match, index)
}
// Output: stream of
}