aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/regexp/example_test.go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2012-11-21 07:03:38 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2012-11-21 07:03:38 +0000
commitfabcaa8df3d6eb852b87821ef090d31d222870b7 (patch)
tree72455aea0286937aa08cc141e5efc800e4626577 /libgo/go/regexp/example_test.go
parenta51fb17f48428e7cfc96a72a9f9f87901363bb6b (diff)
downloadgcc-fabcaa8df3d6eb852b87821ef090d31d222870b7.zip
gcc-fabcaa8df3d6eb852b87821ef090d31d222870b7.tar.gz
gcc-fabcaa8df3d6eb852b87821ef090d31d222870b7.tar.bz2
libgo: Update to current version of master library.
From-SVN: r193688
Diffstat (limited to 'libgo/go/regexp/example_test.go')
-rw-r--r--libgo/go/regexp/example_test.go22
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 0000000..aa92e0b
--- /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
+}