FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sh/pattern/example_test.go at master · ssssyui/sh · GitHub
ssssyui
/
sh
Public
forked from
mvdan/sh
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sh
/
pattern
/
example_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
54 lines (44 loc) · 897 Bytes
Breadcrumbs
sh
/
pattern
/
example_test.go
Copy path
File metadata and controls
54 lines (44 loc) · 897 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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*
// (?s)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
}
Back
|
FazBrowse Home
|
New Git URL