diff options
Diffstat (limited to 'libgo/go/regexp/example_test.go')
-rw-r--r-- | libgo/go/regexp/example_test.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/libgo/go/regexp/example_test.go b/libgo/go/regexp/example_test.go new file mode 100644 index 00000000000..aa92e0b58bc --- /dev/null +++ b/libgo/go/regexp/example_test.go @@ -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 +} |