-
-
Notifications
You must be signed in to change notification settings - Fork 338
/
example_test.go
54 lines (44 loc) · 893 Bytes
/
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
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2019, Daniel Martí <mvdan@mvdan.cc>
// See LICENSE for licensing information
package pattern_test
import (
"fmt"
"regexp"
"mvdan.cc/sh/v3/pattern"
)
func ExampleRegexp() {
pat := "foo?bar*"
fmt.Println(pat)
expr, err := pattern.Regexp(pat, 0)
if err != nil {
return
}
fmt.Println(expr)
rx := regexp.MustCompile(expr)
fmt.Println(rx.MatchString("foo bar baz"))
fmt.Println(rx.MatchString("foobarbaz"))
// Output:
// foo?bar*
// foo.bar.*
// true
// false
}
func ExampleQuoteMeta() {
pat := "foo?bar*"
const mode = 0
fmt.Println(pat)
quoted := pattern.QuoteMeta(pat, mode)
fmt.Println(quoted)
expr, err := pattern.Regexp(quoted, mode)
if err != nil {
return
}
rx := regexp.MustCompile(expr)
fmt.Println(rx.MatchString("foo bar baz"))
fmt.Println(rx.MatchString("foo?bar*"))
// Output:
// foo?bar*
// foo\?bar\*
// false
// true
}