mirror of
https://github.com/golang/go
synced 2024-11-19 17:04:41 -07:00
regexp: add simple package-level example
Update #4125 R=golang-dev, r CC=golang-dev https://golang.org/cl/6846045
This commit is contained in:
parent
7f70bb5913
commit
e33b9f7815
22
src/pkg/regexp/example_test.go
Normal file
22
src/pkg/regexp/example_test.go
Normal file
@ -0,0 +1,22 @@
|
||||
package regexp_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
func Example() {
|
||||
// Compile the expression once, usually at init time.
|
||||
// Use raw strings to avoid having to quote the backslashes.
|
||||
var validID = regexp.MustCompile(`^[a-z]+\[[0-9]+\]$`)
|
||||
|
||||
fmt.Println(validID.MatchString("adam[23]"))
|
||||
fmt.Println(validID.MatchString("eve[7]"))
|
||||
fmt.Println(validID.MatchString("Job[48]"))
|
||||
fmt.Println(validID.MatchString("snakey"))
|
||||
// Output:
|
||||
// true
|
||||
// true
|
||||
// false
|
||||
// false
|
||||
}
|
Loading…
Reference in New Issue
Block a user